Java Code Examples for org.apache.commons.cli.Option

The following examples show how to use org.apache.commons.cli.Option. These examples are extracted from open source projects. 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
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
	
	Options options = EQTLInteractionAnalyser.OPTIONS;
	
	System.out.println("| Short | Long | Description |");
	System.out.println("|-------|------|-------------|");
	
	for(Object optionO : options.getOptions()){
		Option option = (Option) optionO;
		System.out.print("| -");
		System.out.print(option.getOpt());
		System.out.print(" | --");
		System.out.print(option.getLongOpt());
		System.out.print(" | ");
		System.out.print(option.getDescription());
		System.out.println(" | ");
	}
	
}
 
Example 2
Source Project: botsing   Source File: Main.java    License: Apache License 2.0 6 votes vote down vote up
static void printOptions() {
	Collection<Option> ops = options.getOptions();
	System.out.println("Available options are:");
	ops.forEach((ele) -> {
		System.out.print("-" + ele.getOpt() + " " + ele.getLongOpt());
		if (ele.isRequired()) {
			System.out.print(" [required] ");
		} else {
			System.out.print(" [optional] ");
		}
		System.out.print("type: ");
		if (ele.hasArg()) {
			System.out.print("param");
		} else {
			System.out.print("flag");
		}
		System.out.println(", description: " + ele.getDescription());
	});
	return;
}
 
Example 3
Source Project: cumulusrdf   Source File: Query.java    License: Apache License 2.0 6 votes vote down vote up
@Override
Options getOptions() {
	final Option inputO = new Option("q", "sparql query string");
	inputO.setRequired(true);
	inputO.setArgs(1);

	final Option storageO = new Option("s", "storage layout to use (triple|quad)");
	storageO.setArgs(1);

	final Option helpO = new Option("h", "print help");

	final Options options = new Options();
	options.addOption(inputO);
	options.addOption(storageO);
	options.addOption(helpO);
	
	return options;
}
 
Example 4
@Test
public void testNbMandatoryArgsMatchesWithDescription() {

    // In "submit" and "listjobs" cases nb mandatory args does not match with the description
    if (entry.argNames() != null && !entry.longOpt().equals("submit") && !entry.longOpt().equals("listjobs")) {
        int nbMandatoryArgs = 0;
        String mandatoryArgNames = entry.argNames();

        // Consider only mandatory arguments, not optional arguments, i.e. starting with '['
        if (entry.hasOptionalArg()) {
            mandatoryArgNames = mandatoryArgNames.substring(0, mandatoryArgNames.indexOf("["));
        }
        // Unlimited arguments
        if (mandatoryArgNames.contains("...")) {
            nbMandatoryArgs = Option.UNLIMITED_VALUES;
        }
        // As many mandatory arguments as spaced words
        else if (!mandatoryArgNames.trim().isEmpty()) {
            nbMandatoryArgs = mandatoryArgNames.split(" ").length;
        }

        Assert.assertEquals("Option '" + entry.longOpt() + "' does not have argNames matching number of args",
                            entry.numOfArgs(),
                            nbMandatoryArgs);
    }
}
 
Example 5
Source Project: vividus   Source File: BddStepsCounter.java    License: Apache License 2.0 6 votes vote down vote up
public void countSteps(String[] args) throws ParseException, IOException
{
    Vividus.init();
    CommandLine commandLine;
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    Option directoryOption = new Option("d", "dir", true, "directory to count scenarios in (e.g. story/release).");
    Option topOption = new Option("t", "top", true, "the number of most popular steps");
    options.addOption(directoryOption);
    options.addOption(topOption);
    commandLine = parser.parse(options, args);

    StoryLoader storyLoader = BeanFactory.getBean(StoryLoader.class);
    IPathFinder pathFinder = BeanFactory.getBean(IPathFinder.class);
    String storyLocation = commandLine.hasOption(directoryOption.getOpt())
            ? commandLine.getOptionValue(directoryOption.getOpt()) : DEFAULT_STORY_LOCATION;
    ExtendedConfiguration configuration = BeanFactory.getBean(ExtendedConfiguration.class);

    fillStepList(configuration, storyLoader, pathFinder, storyLocation);
    fillStepCandidates();
    fillStepsWithStats(configuration);
    printResults(commandLine, topOption, System.out);
}
 
Example 6
Source Project: ia-rcade   Source File: TestCommandLineOptionsFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeduceFromMameRuntimeWithBooleanOption ()
        throws FileNotFoundException,
               IOException,
               InterruptedException,
               MameExecutionException {
    
    FakeMameRuntime mame = new FakeMameRuntime();
    List<InputStream> inputStreams = new ArrayList<>();
    inputStreams.add(
        new FileInputStream("src/test/resources/showconfig.txt"));
    inputStreams.add(
        new FileInputStream("src/test/resources/showusage.txt"));
    mame.setInputStreamsToReturn(inputStreams);
    CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
    Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();

    assertTrue(mameOpts.hasOption("waitvsync"));

    Option opt = mameOpts.getOption("waitvsync");

    assertFalse(opt.hasArg());

}
 
Example 7
Source Project: DDMQ   Source File: ServerUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Properties commandLine2Properties(final CommandLine commandLine) {
    Properties properties = new Properties();
    Option[] opts = commandLine.getOptions();

    if (opts != null) {
        for (Option opt : opts) {
            String name = opt.getLongOpt();
            String value = commandLine.getOptionValue(name);
            if (value != null) {
                properties.setProperty(name, value);
            }
        }
    }

    return properties;
}
 
Example 8
Source Project: ant-ivy   Source File: Main.java    License: Apache License 2.0 6 votes vote down vote up
private static Options getOptions() {
    Option dir = Option.builder("d")
        .longOpt("dir")
        .hasArg()
        .desc("give total size of files in given dir")
        .build();
    Option name = Option.builder("n")
        .longOpt("name")
        .hasArg()
        .desc("give total size of files with given name")
        .build();
    Options options = new Options();

    options.addOption(dir);
    options.addOption(name);

    return options;
}
 
Example 9
Source Project: rug-cli   Source File: AbstractCommandInfo.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public final Options globalOptions() {
    Options options = new Options();
    options.addOption("?", "help", false, "Print usage help");
    options.addOption("h", "help", false, "Print usage help");
    options.addOption("X", "error", false, "Print stacktraces");
    options.addOption("V", "verbose", false, "Print verbose output");
    options.addOption(Option.builder("s").longOpt("settings").argName("FILE").hasArg(true)
            .required(false).desc("Use settings file FILE").build());
    options.addOption("q", "quiet", false, "Do not display progress messages");
    options.addOption("n", "noisy", false, "Display more progress messages");
    options.addOption("o", "offline", false, "Use only downloaded archives");
    options.addOption("t", "timer", false, "Print timing information");
    options.addOption("r", "resolver-report", false, "Print dependency tree");
    options.addOption("u", "update", false, "Update dependency resolution");
    options.addOption(Option.builder().longOpt("requires").argName("RUG_VERSION").hasArg(true)
            .required(false).desc("Overwrite the Rug version to RUG_VERSION (Use with Caution)")
            .build());
    options.addOption(Option.builder().longOpt("disable-verification").hasArg(false)
            .required(false).desc("Disable verification of extensions (Use with Caution)")
            .build());
    options.addOption(Option.builder().longOpt("disable-version-check").hasArg(false)
            .required(false).desc("Disable version compatibility check (Use with Caution)")
            .build());
    return options;
}
 
Example 10
Source Project: cumulusrdf   Source File: Load.java    License: Apache License 2.0 6 votes vote down vote up
@Override
Options getOptions() {
	final Option inputO = new Option("i", "Name of file to read");
	inputO.setRequired(true);
	inputO.setArgs(1);

	final Option storageO = new Option("s", "Storage layout to use (triple|quad)");
	storageO.setArgs(1);

	final Option batchO = new Option("b", "Batch size - number of triples (default: 1000)");
	batchO.setArgs(1);

	final Option helpO = new Option("h", "Print help");

	final Options options = new Options();
	options.addOption(inputO);
	options.addOption(storageO);
	options.addOption(batchO);
	options.addOption(helpO);
	
	return options;
}
 
Example 11
Source Project: waltz   Source File: ZooKeeperCli.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option partitionOption = Option.builder("p")
            .longOpt("partition")
            .desc("Specify the partition to un-assign")
            .hasArg()
            .build();
    Option storageOption = Option.builder("s")
            .longOpt("storage")
            .desc("Specify the storage to be un-assigned from, in format of host:port")
            .hasArg()
            .build();
    Option cliCfgOption = Option.builder("c")
            .longOpt("cli-config-path")
            .desc("Specify the cli config file path required for ZooKeeper connection string, ZooKeeper root path")
            .hasArg()
            .build();

    cliCfgOption.setRequired(true);
    partitionOption.setRequired(true);
    storageOption.setRequired(true);

    options.addOption(cliCfgOption);
    options.addOption(partitionOption);
    options.addOption(storageOption);
}
 
Example 12
Source Project: waltz   Source File: ClientCli.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option partitionOption = Option.builder("p")
            .longOpt("partition")
            .desc("Specify the partition id whose max transaction ID to be returned")
            .hasArg()
            .build();
    Option cliCfgOption = Option.builder("c")
            .longOpt("cli-config-path")
            .desc("Specify the cli config file path required for zooKeeper connection string, zooKeeper root path and SSL config")
            .hasArg()
            .build();
    partitionOption.setRequired(true);
    cliCfgOption.setRequired(true);

    options.addOption(partitionOption);
    options.addOption(cliCfgOption);
}
 
Example 13
private void printUsage(Options options) {

    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {
      @Override
      public int compare(Option o1, Option o2) {
        if (o1.isRequired() && !o2.isRequired()) {
          return -1;
        }
        if (!o1.isRequired() && o2.isRequired()) {
          return 1;
        }
        return o1.getOpt().compareTo(o2.getOpt());
      }
    });

    String usage = "gobblin watermarks ";
    formatter.printHelp(usage, options);
  }
 
Example 14
Source Project: flink   Source File: FlinkYarnSessionCli.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isYarnPropertiesFileMode(CommandLine commandLine) {
	boolean canApplyYarnProperties = !commandLine.hasOption(addressOption.getOpt());

	if (canApplyYarnProperties) {
		for (Option option : commandLine.getOptions()) {
			if (allOptions.hasOption(option.getOpt())) {
				if (!isDetachedOption(option)) {
					// don't resume from properties file if yarn options have been specified
					canApplyYarnProperties = false;
					break;
				}
			}
		}
	}

	return canApplyYarnProperties;
}
 
Example 15
Source Project: iotdb-benchmark   Source File: CommandCli.java    License: Apache License 2.0 6 votes vote down vote up
private Options createOptions() {
		Options options = new Options();
		Option help = new Option(HELP_ARGS, false, "Display help information");
		help.setRequired(false);
		options.addOption(help);

//		Option HOST = Option.builder(HOST_ARGS).argName(HOST_NAME).hasArg().desc("Host Name (required)").build();
//		options.addOption(HOST);
//
//		Option PORT = Option.builder(PORT_ARGS).argName(PORT_NAME).hasArg().desc("Port (required)").build();
//		options.addOption(PORT);
//		
//		Option mode = Option.builder(MODE_ARGS).argName(MODE_NAME).hasArg().desc("Mode (required)").build();
//		options.addOption(mode);
//		
//		Option device = Option.builder(DEVICE_ARGS).argName(DEVICE_NAME).hasArg().desc("Device number (optional)").build();
//		options.addOption(device);
//		
//		Option sensor = Option.builder(SENSOR_ARGS).argName(SENSOR_NAME).hasArg().desc("Sensor number (optional)").build();
//		options.addOption(sensor);
		
		Option config = Option.builder(CONFIG_ARGS).argName(CONFIG_NAME).hasArg().desc("Config file path (optional)").build();
		options.addOption(config);
		
		return options;
	}
 
Example 16
Source Project: attic-stratos   Source File: DeleteApplicationCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int execute(StratosCommandContext context, String[] args, Option[] alreadyParsedOpts) throws CommandException {
    if (log.isDebugEnabled()) {
        log.debug("Executing {} command...", getName());
    }
    if (args != null && args.length == 1) {
        String id = args[0];
        if (log.isDebugEnabled()) {
            log.debug("Getting delete application id {}", id);
        }
        RestCommandLineService.getInstance().deleteApplication(id);
        return CliConstants.COMMAND_SUCCESSFULL;
    } else {
        context.getStratosApplication().printUsage(getName());
        return CliConstants.COMMAND_FAILED;
    }
}
 
Example 17
Source Project: flink   Source File: FlinkYarnSessionCli.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isYarnPropertiesFileMode(CommandLine commandLine) {
	boolean canApplyYarnProperties = !commandLine.hasOption(addressOption.getOpt());

	if (canApplyYarnProperties) {
		for (Option option : commandLine.getOptions()) {
			if (allOptions.hasOption(option.getOpt())) {
				if (!isDetachedOption(option)) {
					// don't resume from properties file if yarn options have been specified
					canApplyYarnProperties = false;
					break;
				}
			}
		}
	}

	return canApplyYarnProperties;
}
 
Example 18
@Override
public int execute(StratosCommandContext context, String[] args, Option[] alreadyParsedOpts) throws CommandException {
    if (log.isDebugEnabled()) {
        log.debug("Executing {} command...", getName());
    }
    if (args != null && args.length == 1) {
        String applicationId = args[0];
        if (log.isDebugEnabled()) {
            log.debug("Getting delete application id {}", applicationId);
        }
        RestCommandLineService.getInstance().deleteApplicationSignup(applicationId);
        return CliConstants.COMMAND_SUCCESSFULL;
    } else {
        context.getStratosApplication().printUsage(getName());
        return CliConstants.COMMAND_FAILED;
    }
}
 
Example 19
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("c", "clusterModel", false, "clusterModel");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}
 
Example 20
Source Project: Rhombus   Source File: RcliWithExistingKeyspace.java    License: MIT License 5 votes vote down vote up
public Options getCommandOptions(){
	Options ret = super.getCommandOptions();
	Option keyspaceName = OptionBuilder.withArgName("name")
			.hasArg()
			.withDescription("Name of the existing keyspace to be used")
			.create( "keyspace" );
	ret.addOption(keyspaceName);
	return ret;
}
 
Example 21
Source Project: stratio-cassandra   Source File: Legacy.java    License: Apache License 2.0 5 votes vote down vote up
public static void printHelpMessage()
{
    System.out.println("Usage: ./bin/cassandra-stress legacy [options]\n\nOptions:");
    System.out.println("THIS IS A LEGACY SUPPORT MODE");

    for(Object o : availableOptions.getOptions())
    {
        Option option = (Option) o;
        String upperCaseName = option.getLongOpt().toUpperCase();
        System.out.println(String.format("-%s%s, --%s%s%n\t\t%s%n", option.getOpt(), (option.hasArg()) ? " "+upperCaseName : "",
                option.getLongOpt(), (option.hasArg()) ? "="+upperCaseName : "", option.getDescription()));
    }
}
 
Example 22
Source Project: rocketmq   Source File: ConsumerConnectionSubCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "consumerGroup", true, "consumer group name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example 23
Source Project: incubator-heron   Source File: RuntimeManagerMain.java    License: Apache License 2.0 5 votes vote down vote up
private static Options constructHelpOptions() {
  Options options = new Options();
  Option help = Option.builder("h")
      .desc("List all options and their description")
      .longOpt("help")
      .build();

  options.addOption(help);
  return options;
}
 
Example 24
Source Project: singer   Source File: ThriftLogDumper.java    License: Apache License 2.0 5 votes vote down vote up
private static Options buildOptions() {
  Option input = new Option("i", "input", true, "Input thrift logger log file");
  input.setRequired(true);

  Option output = new Option("o", "output", true, "Output file. Default: STDOUT");
  Option maxMessageSize =
      new Option(null, "max-message-size", true,
          "Max thrift message size allowed. Default: 16384");
  Option startOffset = new Option(null, "offset", true,
      "Byte offset from the beginning of the file to start reading. Default: 0");
  Option numOfMessages =
      new Option("n", "number-of-messages", true, "Number of messages to dump. Default: INTMAX");
  Option noTimestamp = new Option(null, "no-timestamp", false, "Output message only");
  Option toJson = new Option(null, "json", false, "Output as JSON format");
  Option pretty = new Option(null, "pretty", false, "Prettifies the JSON formatted messages");
  Option thriftSchema =
      new Option(null, "thrift-schema", true,
          "Thrift schema class used for deserialization. Default: cast message body to String.");

  Options options = new Options();
  options
      .addOption(input)
      .addOption(output)
      .addOption(maxMessageSize)
      .addOption(startOffset)
      .addOption(numOfMessages)
      .addOption(noTimestamp)
      .addOption(toJson)
      .addOption(pretty)
      .addOption(thriftSchema);
  return options;
}
 
Example 25
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example 26
Source Project: Flink-CEPplus   Source File: DeploymentEntry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses the given command line options from the deployment properties. Ignores properties
 * that are not defined by options.
 */
public CommandLine getCommandLine(Options commandLineOptions) throws Exception {
	final List<String> args = new ArrayList<>();

	properties.asMap().forEach((k, v) -> {
		// only add supported options
		if (commandLineOptions.hasOption(k)) {
			final Option o = commandLineOptions.getOption(k);
			final String argument = "--" + o.getLongOpt();
			// options without args
			if (!o.hasArg()) {
				final Boolean flag = Boolean.parseBoolean(v);
				// add key only
				if (flag) {
					args.add(argument);
				}
			}
			// add key and value
			else if (!o.hasArgs()) {
				args.add(argument);
				args.add(v);
			}
			// options with multiple args are not supported yet
			else {
				throw new IllegalArgumentException("Option '" + o + "' is not supported yet.");
			}
		}
	});

	return CliFrontendParser.parse(commandLineOptions, args.toArray(new String[args.size()]), true);
}
 
Example 27
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example 28
Source Project: flink   Source File: HadoopUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@link ParameterTool} for the arguments parsed by {@link GenericOptionsParser}.
 *
 * @param args Input array arguments. It should be parsable by {@link GenericOptionsParser}
 * @return A {@link ParameterTool}
 * @throws IOException If arguments cannot be parsed by {@link GenericOptionsParser}
 * @see GenericOptionsParser
 */
public static ParameterTool paramsFromGenericOptionsParser(String[] args) throws IOException {
	Option[] options = new GenericOptionsParser(args).getCommandLine().getOptions();
	Map<String, String> map = new HashMap<String, String>();
	for (Option option : options) {
		String[] split = option.getValue().split("=");
		map.put(split[0], split[1]);
	}
	return ParameterTool.fromMap(map);
}
 
Example 29
Source Project: helix   Source File: RestAdminApplication.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
  Option helpOption =
      OptionBuilder.withLongOpt(HELP).withDescription("Prints command-line options info")
          .create();
  helpOption.setArgs(0);
  helpOption.setRequired(false);
  helpOption.setArgName("print help message");

  Option zkServerOption =
      OptionBuilder.withLongOpt(ZKSERVERADDRESS).withDescription("Provide zookeeper address")
          .create();
  zkServerOption.setArgs(1);
  zkServerOption.setRequired(true);
  zkServerOption.setArgName("ZookeeperServerAddress(Required)");

  Option portOption =
      OptionBuilder.withLongOpt(PORT).withDescription("Provide web service port").create();
  portOption.setArgs(1);
  portOption.setRequired(false);
  portOption.setArgName("web service port, default: " + DEFAULT_PORT);

  Options options = new Options();
  options.addOption(helpOption);
  options.addOption(zkServerOption);
  options.addOption(portOption);

  return options;
}
 
Example 30
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "consumerGroup", true, "consumer group name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}