Esempio n. 1
0
  public void test11456() {
    // Posix
    Options options = new Options();
    options.addOption(OptionBuilder.hasOptionalArg().create('a'));
    options.addOption(OptionBuilder.hasArg().create('b'));
    String[] args = new String[] {"-a", "-bvalue"};

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine cmd = parser.parse(options, args);
      assertEquals(cmd.getOptionValue('b'), "value");
    } catch (ParseException exp) {
      fail("Unexpected Exception: " + exp.getMessage());
    }

    // GNU
    options = new Options();
    options.addOption(OptionBuilder.hasOptionalArg().create('a'));
    options.addOption(OptionBuilder.hasArg().create('b'));
    args = new String[] {"-a", "-b", "value"};

    parser = new GnuParser();

    try {
      CommandLine cmd = parser.parse(options, args);
      assertEquals(cmd.getOptionValue('b'), "value");
    } catch (ParseException exp) {
      fail("Unexpected Exception: " + exp.getMessage());
    }
  }
Esempio n. 2
0
  private static Options createOptions() {
    Options options = new Options();

    OptionBuilder.withDescription("Show this help");
    options.addOption(OptionBuilder.create(CMD_HELP));

    OptionBuilder.withArgName("port");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withDescription("The port to run the Nutch Server. Default port 8081");
    options.addOption(OptionBuilder.create(CMD_PORT));

    OptionBuilder.withArgName("host");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withDescription("The host to bind the Nutch Server to. Default is localhost.");
    options.addOption(OptionBuilder.create(CMD_PORT));

    return options;
  }