org.apache.commons.cli.UnrecognizedOptionException Java Examples

The following examples show how to use org.apache.commons.cli.UnrecognizedOptionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseExceptionProcessor.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String process(ParseException e) {
    if (e instanceof MissingOptionException) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> options = ((MissingOptionException) e).getMissingOptions().iterator();
        while (options.hasNext()) {
            sb.append(options.next());
            if (options.hasNext()) {
                sb.append(", ");
            }
        }
        return String.format("Missing required option(s) %s.", sb.toString());
    }
    else if (e instanceof MissingArgumentException) {
        return String.format("%s is missing a required argument.",
                ((MissingArgumentException) e).getOption());
    }
    else if (e instanceof UnrecognizedOptionException) {
        return String.format("%s is not a valid option.",
                ((UnrecognizedOptionException) e).getOption());
    }
    else {
        return String.format("%s.", e.getMessage());
    }
}
 
Example #2
Source File: ArgsOnlyCommand.java    From parquet-tools with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine options) throws Exception {
  String[] args = options.getArgs();
  if (args.length < min) {
    throw new MissingArgumentException("missing required arguments");
  }

  if (args.length > max) {
    throw new UnrecognizedOptionException("unknown extra argument \"" + args[max] + "\"");
  }
}
 
Example #3
Source File: ArgsOnlyCommand.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine options) throws Exception {
  String[] args = options.getArgs();
  if (args.length < min) {
    throw new MissingArgumentException("missing required arguments");
  }

  if (args.length > max) {
    throw new UnrecognizedOptionException("unknown extra argument \"" + args[max] + "\"");
  }
}
 
Example #4
Source File: ArgumentParserTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testParseArgumentsUnrecognizedOptionException() throws ParseException
{
    ArgumentParser argParser = new ArgumentParser("");
    argParser.addArgument("a", "configured_option", false, "Some flag parameter", false);
    argParser.parseArguments(new String[] {"-b", "unrecognized_option"});
}
 
Example #5
Source File: CommandLineTest.java    From keyword-optimizer with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the specifying some random argument work throws an exception.
 */
@Test
public void checkRandomArgDoesNotWork() throws KeywordOptimizerException {
  thrown.expect(KeywordOptimizerException.class);
  thrown.expectCause(isA(UnrecognizedOptionException.class));
  KeywordOptimizer.run("-x");
}
 
Example #6
Source File: HalyardElasticIndexerTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testRunInvalid() throws Exception {
    new HalyardElasticIndexer().run(new String[]{"-invalid"});
}
 
Example #7
Source File: HalyardBulkExportTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testRunInvalid() throws Exception {
    new HalyardBulkExport().run(new String[]{"--invalid"});
}
 
Example #8
Source File: HalyardStatsTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testRunInvalid() throws Exception {
    new HalyardStats().run(new String[]{"-invalid"});
}
 
Example #9
Source File: HalyardSummaryTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testRunInvalid() throws Exception {
    new HalyardSummary().run(new String[]{"-invalid"});
}
 
Example #10
Source File: HalyardMainTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testInvalid() throws Exception {
    HalyardMain.main(new String[]{"invalid"});
}
 
Example #11
Source File: VividusInitializationCheckerTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testUnknownOptionIsPresent() throws Exception
{
    VividusInitializationChecker.main(new String[] { "--any" });
}
 
Example #12
Source File: HalyardBulkDeleteTest.java    From Halyard with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void testRunInvalid() throws Exception {
    new HalyardBulkDelete().run(new String[]{"-invalid"});
}
 
Example #13
Source File: MainTest.java    From nifi-config with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnrecognizedOptionException.class)
public void mainPrintUsage5Test() throws Exception {
    Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "undeploy", "-userErr", "user"});
}
 
Example #14
Source File: RdfLint.java    From rdflint with MIT License 4 votes vote down vote up
/**
 * rdflint entry point.
 */
public static void main(String[] args) throws ParseException, IOException {

  // Parse CommandLine Parameter
  Options options = new Options();
  options.addOption("baseuri", true, "RDF base URI");
  options.addOption("targetdir", true, "Target Directory Path");
  options.addOption("outputdir", true, "Output Directory Path");
  options.addOption("origindir", true, "Origin Dataset Directory Path");
  options.addOption("config", true, "Configuration file Path");
  options.addOption("suppress", true, "Suppress problems file Path");
  options.addOption("minErrorLevel", true,
      "Minimal logging level which is considered an error, e.g. INFO, WARN, ERROR");
  options.addOption("i", false, "Interactive mode");
  options.addOption("ls", false, "Language Server mode (experimental)");
  options.addOption("h", false, "Print usage");
  options.addOption("v", false, "Print version");
  options.addOption("vv", false, "Verbose logging (for debugging)");

  CommandLine cmd = null;

  try {
    CommandLineParser parser = new DefaultParser();
    cmd = parser.parse(options, args);
  } catch (UnrecognizedOptionException e) {
    System.out.println("Unrecognized option: " + e.getOption()); // NOPMD
    System.exit(1);
  }

  // print version
  if (cmd.hasOption("v")) {
    System.out.println("rdflint " + VERSION); // NOPMD
    return;
  }

  // print usage
  if (cmd.hasOption("h")) {
    HelpFormatter f = new HelpFormatter();
    f.printHelp("rdflint [options]", options);
    return;
  }

  // verbose logging mode
  if (cmd.hasOption("vv")) {
    Logger.getLogger("com.github.imas.rdflint").setLevel(Level.TRACE);
  }

  // Execute Language Server Mode
  if (cmd.hasOption("ls")) {
    RdfLintLanguageServer server = new RdfLintLanguageServer();
    Launcher<LanguageClient> launcher = LSPLauncher
        .createServerLauncher(server, System.in, System.out);
    LanguageClient client = launcher.getRemoteProxy();
    server.connect(client);
    launcher.startListening();
    return;
  }

  // Set parameter
  Map<String, String> cmdOptions = new ConcurrentHashMap<>();
  for (String key :
      Arrays.asList("targetdir", "config", "suppress", "outputdir", "baseuri", "origindir")) {
    if (cmd.hasOption(key)) {
      cmdOptions.put(key, cmd.getOptionValue(key));
    }
  }

  // Main procedure
  if (cmd.hasOption("i")) {
    // Execute Interactive mode
    InteractiveMode imode = new InteractiveMode();
    imode.execute(cmdOptions);
  } else {
    // Execute linter
    RdfLint lint = new RdfLint();
    RdfLintParameters params = ConfigurationLoader.loadParameters(cmdOptions);
    LintProblemSet problems = lint.lintRdfDataSet(params, params.getTargetDir());
    if (problems.hasProblem()) {
      Path problemsPath = Paths.get(params.getOutputDir() + "/rdflint-problems.yml");
      LintProblemFormatter.out(System.out, problems);
      LintProblemFormatter.yaml(Files.newOutputStream(problemsPath), problems);
      final String minErrorLevel = cmd.getOptionValue("minErrorLevel", "WARN");
      final LintProblem.ErrorLevel errorLevel = LintProblem.ErrorLevel.valueOf(minErrorLevel);
      if (problems.hasProblemOfLevelOrWorse(errorLevel)) {
        System.exit(1);
      }
    }
  }
}
 
Example #15
Source File: BddScenariosCounterTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Test
public void testUnknownOptionIsPresent()
{
    assertThrows(UnrecognizedOptionException.class, () ->
            BddScenariosCounter.main(new String[] { "--any", DIR_VALUE}));
}
 
Example #16
Source File: KnownIssueValidatorTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Test
public void testUnknownOptionIsPresent()
{
    assertThrows(UnrecognizedOptionException.class, () ->
            KnownIssueValidator.main(new String[]{"--any"}));
}
 
Example #17
Source File: BddStepsCounterTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Test
public void testUnknownOptionIsPresent()
{
    assertThrows(UnrecognizedOptionException.class,
        () ->  BddStepsCounter.main(new String[] { "--any", DIR_VALUE }));
}