in languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java [34:178]
CommandLineOptions parseOptions(String[] args) {
if (args.length < 1 || args.length > 14) {
throw new WrongParameterNumberException();
}
CommandLineOptions options = new CommandLineOptions();
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--version")) {
options.setPrintVersion(true);
} else if (args[i].equals("--list")) {
options.setPrintLanguages(true);
} else if (args[i].equals("-h") || args[i].equals("-help") || args[i].equals("--help") || args[i].equals("--?")) {
options.setPrintUsage(true);
} else if (args[i].equals("-adl") || args[i].equals("--autoDetect")) { // set autoDetect flag
options.setAutoDetect(true);
} else if (args[i].equals("-v") || args[i].equals("--verbose")) {
options.setVerbose(true);
} else if (args[i].equals("--line-by-line")) {
options.setLineByLine(true);
} else if (args[i].equals("--enable-temp-off")) {
options.setEnableTempOff(true);
} else if (args[i].equals("--clean-overlapping")) {
options.setCleanOverlapping(true);
} else if (args[i].equals("--level")) {
String level = args[++i];
try {
options.setLevel(JLanguageTool.Level.valueOf(level));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unknown level '" + level + "' - currently, only 'PICKY' is supported");
}
} else if (args[i].equals("-t") || args[i].equals("--taggeronly")) {
options.setTaggerOnly(true);
if (options.isListUnknown()) {
throw new IllegalArgumentException("You cannot list unknown words when tagging only");
}
if (options.isApplySuggestions()) {
throw new IllegalArgumentException("You cannot apply suggestions when tagging only");
}
} else if (args[i].equals("-r") || args[i].equals("--recursive")) {
options.setRecursive(true);
} else if (args[i].equals("-b2") || args[i].equals("--bitext")) {
options.setBitext(true);
} else if (args[i].equals("-eo") || args[i].equals("--enabledonly")) {
if (options.getDisabledRules().size() > 0) {
throw new IllegalArgumentException("You cannot specify both disabled rules and enabledonly");
}
options.setUseEnabledOnly();
} else if (args[i].equals("-d") || args[i].equals("--disable")) {
if (options.isUseEnabledOnly()) {
throw new IllegalArgumentException("You cannot specify both disabled rules and enabledonly");
}
checkArguments("-d/--disable", i, args);
String rules = args[++i];
options.setDisabledRules(Arrays.asList(rules.split(",")));
} else if (args[i].equals("-e") || args[i].equals("--enable")) {
checkArguments("-e/--enable", i, args);
String rules = args[++i];
options.setEnabledRules(Arrays.asList(rules.split(",")));
} else if (args[i].equals("--enablecategories")) {
checkArguments("--enablecategories", i, args);
String categories = args[++i];
options.setEnabledCategories(Arrays.asList(categories.split(",")));
} else if (args[i].equals("--disablecategories")) {
checkArguments("--disablecategories", i, args);
String categories = args[++i];
options.setDisabledCategories(Arrays.asList(categories.split(",")));
} else if (args[i].equals("-l") || args[i].equals("--language")) {
checkArguments("-l/--language", i, args);
options.setLanguage(getLanguage(args[++i]));
} else if (args[i].equals("-m") || args[i].equals("--mothertongue")) {
checkArguments("-m/--mothertongue", i, args);
options.setMotherTongue(getLanguage(args[++i]));
} else if (args[i].equals("--languagemodel")) {
checkArguments("--languagemodel", i, args);
options.setLanguageModel(new File(args[++i]));
} else if (args[i].equals("--fasttextmodel")) {
checkArguments("--fasttextmodel", i, args);
options.setFasttextModel(new File(args[++i]));
} else if (args[i].equals("--fasttextbinary")) {
checkArguments("--fasttextbinary", i, args);
options.setFasttextBinary(new File(args[++i]));
} else if (args[i].equals("--rulefile")) {
checkArguments("--rulefile", i, args);
options.setRuleFile(args[++i]);
} else if (args[i].equals("--remoterules")) {
checkArguments("--remoterules", i, args);
options.setRemoteRulesFile(args[++i]);
} else if (args[i].equals("--falsefriends")) {
checkArguments("--falsefriends", i, args);
options.setFalseFriendFile(args[++i]);
} else if (args[i].equals("--bitextrules")) {
checkArguments("--bitextrules", i, args);
options.setBitextRuleFile(args[++i]);
} else if (args[i].equals("-c") || args[i].equals("--encoding")) {
checkArguments("-c/--encoding", i, args);
options.setEncoding(args[++i]);
} else if (args[i].equals("-u") || args[i].equals("--list-unknown")) {
options.setListUnknown(true);
if (options.isTaggerOnly()) {
throw new IllegalArgumentException("You cannot list unknown words when tagging only");
}
} else if (args[i].equals("-b")) {
options.setSingleLineBreakMarksParagraph(true);
} else if (args[i].equals("--json")) {
options.setJsonFormat();
if (options.isApplySuggestions()) {
throw new IllegalArgumentException("JSON output format makes no sense for automatic application of suggestions");
}
if (options.isLineByLine()) {
throw new IllegalArgumentException("JSON output format is not implemented for \"line by line\" analysis");
}
if (options.isBitext()) {
throw new IllegalArgumentException("JSON output format is not implemented for Bitext");
}
if (options.isListUnknown()) {
throw new IllegalArgumentException("You cannot list unknown words in JSON output format");
}
} else if (args[i].equals("-a") || args[i].equals("--apply")) {
options.setApplySuggestions(true);
if (options.isTaggerOnly()) {
throw new IllegalArgumentException("You cannot apply suggestions when tagging only");
}
if (options.isJsonFormat()) {
throw new IllegalArgumentException("JSON output format makes no sense for automatic application of suggestions");
}
} else if (args[i].equals("-p") || args[i].equals("--profile")) {
options.setProfile(true);
if (options.isJsonFormat()) {
throw new IllegalArgumentException("JSON output format makes no sense for profiling");
}
if (options.isApplySuggestions()) {
throw new IllegalArgumentException("Applying suggestions makes no sense for profiling");
}
if (options.isTaggerOnly()) {
throw new IllegalArgumentException("Tagging makes no sense for profiling");
}
} else if (args[i].equals("--xmlfilter")) {
options.setXmlFiltering(true);
} else if (i == args.length - 1) {
options.setFilename(args[i]);
} else {
throw new UnknownParameterException("Unknown parameter: " + args[i]);
}
}
return options;
}