Skip to content

Commit

Permalink
Added a better error message, if no valid language was supplied.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Jan 19, 2024
1 parent 1070c0f commit 741a128
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 741a128

Please sign in to comment.