Skip to content

Commit

Permalink
Merge pull request #1493 from jplag/feature/cli-invalid-language-erro…
Browse files Browse the repository at this point in the history
…r-message

Added a better error message, if no valid language was supplied.
  • Loading branch information
tsaglam authored Jan 22, 2024
2 parents ad664c6 + 741a128 commit 3c9af11
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.File;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -58,6 +59,7 @@ public final class CLI {

private static final String IMPOSSIBLE_EXCEPTION = "This should not have happened."
+ " Please create an issue on github (https://github.com/jplag/JPlag/issues) with the entire output.";
private static final String UNKOWN_LANGAUGE_EXCEPTION = "Language %s does not exists. Available languages are: %s";

private static final String DESCRIPTION_PATTERN = "%nJPlag - %s%n%s%n%n";

Expand Down Expand Up @@ -140,6 +142,12 @@ public ParseResult parseOptions(String... args) throws CliException {
commandLine.getExecutionStrategy().execute(result);
}
return result;
} catch (CommandLine.ParameterException e) {
if (e.getArgSpec().isOption() && Arrays.asList(((OptionSpec) e.getArgSpec()).names()).contains("-l")) {
throw new CliException(String.format(UNKOWN_LANGAUGE_EXCEPTION, e.getValue(),
String.join(", ", LanguageLoader.getAllAvailableLanguageIdentifiers())));
}
throw new CliException("Error during parsing", e);
} catch (CommandLine.PicocliException e) {
throw new CliException("Error during parsing", e);
}
Expand Down

0 comments on commit 3c9af11

Please sign in to comment.