Skip to content

Added a better error message, if no valid language was supplied. #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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