From 741a128956b68e0aca22cdc70d655d5b60b4a4bc Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 19 Jan 2024 11:37:33 +0100 Subject: [PATCH] Added a better error message, if no valid language was supplied. --- cli/src/main/java/de/jplag/cli/CLI.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/src/main/java/de/jplag/cli/CLI.java b/cli/src/main/java/de/jplag/cli/CLI.java index be94fa083..029e6455d 100644 --- a/cli/src/main/java/de/jplag/cli/CLI.java +++ b/cli/src/main/java/de/jplag/cli/CLI.java @@ -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; @@ -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"; @@ -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); }