org.apache.commons.cli.Option Java Examples

The following examples show how to use org.apache.commons.cli.Option. 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: DeleteApplicationSignupCommand.java    From attic-stratos with 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 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 #2
Source File: Query.java    From cumulusrdf with 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 #3
Source File: Main.java    From botsing with 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 #4
Source File: TestCommandLineOptionsFactory.java    From ia-rcade with 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 #5
Source File: BddStepsCounter.java    From vividus with 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 File: CommandSetTest.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #7
Source File: createOptionsListForManual.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 #8
Source File: ServerUtil.java    From DDMQ with 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 #9
Source File: Main.java    From ant-ivy with 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 #10
Source File: AbstractCommandInfo.java    From rug-cli with 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 #11
Source File: Load.java    From cumulusrdf with 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 #12
Source File: ZooKeeperCli.java    From waltz with 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 #13
Source File: ClientCli.java    From waltz with 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 #14
Source File: StateStoreBasedWatermarkStorageCli.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: FlinkYarnSessionCli.java    From flink with 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 #16
Source File: CommandCli.java    From iotdb-benchmark with 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 #17
Source File: DeleteApplicationCommand.java    From attic-stratos with 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 #18
Source File: FlinkYarnSessionCli.java    From flink with 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 #19
Source File: ColumnStatsTool.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
public static Options createOptions( final String[] args ){
  Option input = OptionBuilder.
    withLongOpt("input").
    withDescription("Input file path.  \"-\" standard input").
    hasArg().
    isRequired().
    withArgName("input").
    create( 'i' );

  Option output = OptionBuilder.
    withLongOpt("output").
    withDescription("output file path. \"-\" standard output").
    hasArg().
    isRequired().
    withArgName("output").
    create( 'o' );

  Option help = OptionBuilder.
    withLongOpt("help").
    withDescription("help").
    withArgName("help").
    create( 'h' );

  Options  options = new Options();

  return options
    .addOption( input )
    .addOption( output )
    .addOption( help );
}
 
Example #20
Source File: StorageCli.java    From waltz with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option storageOption = Option.builder("s")
            .longOpt("storage")
            .desc("Specify storage in format of host:admin_port")
            .hasArg()
            .build();
    Option storagePortOption = Option.builder("sp")
            .longOpt("storage-port")
            .desc("Specify the port of storage, where port is non-admin port")
            .hasArg()
            .build();
    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();
    Option offlineOption = Option.builder("o")
            .longOpt("offline")
            .desc("Check max transaction ID when storage is offline")
            .hasArg(false)
            .build();
    storageOption.setRequired(true);
    storagePortOption.setRequired(true);
    partitionOption.setRequired(true);
    cliCfgOption.setRequired(true);
    offlineOption.setRequired(false);

    options.addOption(storageOption);
    options.addOption(storagePortOption);
    options.addOption(partitionOption);
    options.addOption(cliCfgOption);
    options.addOption(offlineOption);
}
 
Example #21
Source File: StorageCli.java    From waltz with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    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();
    cliCfgOption.setRequired(true);

    options.addOption(cliCfgOption);
}
 
Example #22
Source File: TopicStatusSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("t", "topic", true, "topic name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example #23
Source File: JobsGetCommand.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Options getOptions() {
    Options options = new Options();
    options.addOption(Option.builder("a").longOpt("archived").hasArg(false)
            .desc("If set, return also archived jobs").build());
    options.addOption(Option.builder("t").longOpt("type")
            .desc("Search by job type").build());
    options.addOption(Option.builder("s").longOpt("page_size").hasArg().type(Number.class)
            .desc("Maximum number of items to return").build());
    options.addOption(Option.builder("n").longOpt("page_number").hasArg().type(Number.class)
            .desc("Number of page to return starting from 0").build());
    options.addOption(Option.builder("f").longOpt("fields").hasArg()
            .desc("Comma separated list of fields to return").build());
    return options;
}
 
Example #24
Source File: ReactionRenderer.java    From act with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  Options opts = new Options();
  for (Option.Builder b : OPTION_BUILDERS) {
    opts.addOption(b.build());
  }

  CommandLine cl = null;
  try {
    CommandLineParser parser = new DefaultParser();
    cl = parser.parse(opts, args);
  } catch (ParseException e) {
    System.err.format("Argument parsing failed: %s\n", e.getMessage());
    HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
    System.exit(1);
  }

  if (cl.hasOption("help")) {
    HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
    return;
  }

  Integer height = Integer.parseInt(cl.getOptionValue(OPTION_HEIGHT, "1000"));
  Integer width = Integer.parseInt(cl.getOptionValue(OPTION_WIDTH, "1000"));
  Boolean representCofactors = cl.hasOption(OPTION_COFACTOR) && Boolean.parseBoolean(cl.getOptionValue(OPTION_COFACTOR));

  NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB));

  for (String val : cl.getOptionValues(OPTION_RXN_IDS)) {
    Long reactionId = Long.parseLong(val);
    ReactionRenderer renderer = new ReactionRenderer(cl.getOptionValue(OPTION_FILE_FORMAT), width, height);
    renderer.drawReaction(api.getReadDB(), reactionId, cl.getOptionValue(OPTION_DIR_PATH), representCofactors);
    LOGGER.info(renderer.getSmartsForReaction(api.getReadDB(), reactionId, representCofactors));
  }
}
 
Example #25
Source File: RcliWithExistingKeyspace.java    From Rhombus with 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 #26
Source File: ArgsFactory.java    From InflatableDonkey with MIT License 5 votes vote down vote up
static Arg filterItemType() {
    Option option = Option.builder()
            .longOpt("item-type")
            .desc("Only download the specified item type/s: " + PropertyItemType.DETAILS)
            .argName("item-type/s")
            .hasArgs()
            .build();
    return new Arg(Property.FILTER_ASSET_ITEM_TYPE, option, mapEnum(PropertyItemType::valueOf));
}
 
Example #27
Source File: Legacy.java    From stratio-cassandra with 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 #28
Source File: ConsumerProgressSubCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "groupName", true, "consumer group name");
    opt.setRequired(false);
    options.addOption(opt);

    Option opt1 = new Option("t", "topic", true, "topic name");
    opt1.setRequired(false);
    options.addOption(opt1);

    return options;
}
 
Example #29
Source File: WipeWritePermSubCommand.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example #30
Source File: CommandLineApplication.java    From validator with Apache License 2.0 5 votes vote down vote up
private static void warnUnusedOptions(final CommandLine cmd, final Option[] unavailable, final boolean daemon) {
    Arrays.stream(cmd.getOptions()).filter(o -> ArrayUtils.contains(unavailable, o))
            .map(o -> "The option " + o.getLongOpt() + " is not available in daemon mode").forEach(log::error);
    if (daemon && !cmd.getArgList().isEmpty()) {
        log.info("Ignoring test targets in daemon mode");
    }
}