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 Project: rug-cli   Author: atomist-attic   File: ParseExceptionProcessor.java    License: 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 Project: keyword-optimizer   Author: googleads   File: CommandLineTest.java    License: 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 #3
Source Project: herd   Author: FINRAOS   File: ArgumentParserTest.java    License: 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 #4
Source Project: parquet-mr   Author: apache   File: ArgsOnlyCommand.java    License: 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 #5
Source Project: parquet-tools   Author: wesleypeck   File: ArgsOnlyCommand.java    License: 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 #6
Source Project: vividus   Author: vividus-framework   File: VividusInitializationCheckerTests.java    License: 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 #7
Source Project: vividus   Author: vividus-framework   File: BddStepsCounterTests.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testUnknownOptionIsPresent()
{
    assertThrows(UnrecognizedOptionException.class,
        () ->  BddStepsCounter.main(new String[] { "--any", DIR_VALUE }));
}
 
Example #8
Source Project: vividus   Author: vividus-framework   File: KnownIssueValidatorTests.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testUnknownOptionIsPresent()
{
    assertThrows(UnrecognizedOptionException.class, () ->
            KnownIssueValidator.main(new String[]{"--any"}));
}
 
Example #9
Source Project: vividus   Author: vividus-framework   File: BddScenariosCounterTests.java    License: 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 #10
Source Project: rdflint   Author: imas   File: RdfLint.java    License: 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 #11
Source Project: nifi-config   Author: hermannpencole   File: MainTest.java    License: 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 #12
Source Project: Halyard   Author: Merck   File: HalyardBulkDeleteTest.java    License: 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 Project: Halyard   Author: Merck   File: HalyardElasticIndexerTest.java    License: 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 #14
Source Project: Halyard   Author: Merck   File: HalyardMainTest.java    License: 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 #15
Source Project: Halyard   Author: Merck   File: HalyardSummaryTest.java    License: 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 #16
Source Project: Halyard   Author: Merck   File: HalyardStatsTest.java    License: 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 #17
Source Project: Halyard   Author: Merck   File: HalyardBulkExportTest.java    License: 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"});
}