Example usage for org.apache.commons.cli OptionBuilder withArgName

List of usage examples for org.apache.commons.cli OptionBuilder withArgName

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withArgName.

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:de.weltraumschaf.groundzero.opt.commons.OptionsConfiguration.java

/**
 * Initializes {@link #options} with all information the options parser needs.
 *///from   www .  j a  v  a 2 s .c  o  m
public OptionsConfiguration() {
    super();
    // w/ argument
    OptionBuilder.withDescription(OptionDescriptor.PATH_PREFIX.getDescription());
    OptionBuilder.withArgName("PATH");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.PATH_PREFIX.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.PATH_PREFIX.getShortOption()));
    OptionBuilder.withDescription(OptionDescriptor.INPUT_ENCODING.getDescription());
    OptionBuilder.withArgName("ENCODING");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.INPUT_ENCODING.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.INPUT_ENCODING.getShortOption()));
    OptionBuilder.withDescription(OptionDescriptor.OUTPUT_ENCODING.getDescription());
    OptionBuilder.withArgName("ENCODING");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.OUTPUT_ENCODING.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.OUTPUT_ENCODING.getShortOption()));

    // w/o argument
    options.addOption(OptionDescriptor.DEBUG.getShortOption(), OptionDescriptor.DEBUG.getLongOption(), false,
            OptionDescriptor.DEBUG.getDescription());
    options.addOption(OptionDescriptor.HELP.getShortOption(), OptionDescriptor.HELP.getLongOption(), false,
            OptionDescriptor.HELP.getDescription());
    options.addOption(OptionDescriptor.VERSION.getShortOption(), OptionDescriptor.VERSION.getLongOption(),
            false, OptionDescriptor.VERSION.getDescription());
}

From source file:jeplus.util.LineEnds.java

protected static Options getCommandLineOptions() {
    Option help = new Option("help", "print this message");

    Option file = OptionBuilder.withArgName("file to convert").hasArg().withDescription(
            "Name of the file to be converted. If a folder name is given, all files in the folder will be converted")
            .isRequired().create("file");
    Option style = OptionBuilder.withArgName("Line-end style").hasArg()
            .withDescription("Style of line ends. Choose between W or L").create("style");
    Option log = OptionBuilder.withArgName("Log configuration").hasArg()
            .withDescription("Logger configuration file. Default=./log4j.cfg").create("log");

    Options options = new Options();

    options.addOption(help);/*from   w  w  w.j av a2  s  . c o m*/
    options.addOption(file);
    options.addOption(style);
    options.addOption(log);

    return options;
}

From source file:ape.NetworkSlowCommand.java

/**
 * The constructor for this command simply creates its Option object (used by
 * the CLI parser)//from   w  w w . java  2  s.  c  o  m
 */
public NetworkSlowCommand() {
    option = OptionBuilder.withArgName("delay> <duration").hasArgs(2).withValueSeparator().withDescription(
            "Delay all network packet delivery by a specified amount of time (in milliseconds) for a period specified in seconds")
            .withLongOpt("network-slow").create("S");
}

From source file:com.example.geomesa.kafka08.KafkaQuickStart.java

public static Options getCommonRequiredOptions() {
    Options options = new Options();

    Option kafkaBrokers = OptionBuilder.withArgName(KAFKA_BROKER_PARAM).hasArg().isRequired()
            .withDescription("The comma-separated list of Kafka brokers, e.g. localhost:9092")
            .create(KAFKA_BROKER_PARAM);
    options.addOption(kafkaBrokers);/* w  ww.  j a  v a  2s.c  o m*/

    Option zookeepers = OptionBuilder.withArgName(ZOOKEEPERS_PARAM).hasArg().isRequired().withDescription(
            "The comma-separated list of Zookeeper nodes that support your Kafka instance, e.g.: zoo1:2181,zoo2:2181,zoo3:2181")
            .create(ZOOKEEPERS_PARAM);
    options.addOption(zookeepers);

    Option zkPath = OptionBuilder.withArgName(ZK_PATH).hasArg()
            .withDescription("Zookeeper's discoverable path for metadata, defaults to /geomesa/ds/kafka")
            .create(ZK_PATH);
    options.addOption(zkPath);

    Option visibility = OptionBuilder.withArgName(VISIBILITY).hasArg().create(VISIBILITY);
    options.addOption(visibility);

    Option automated = OptionBuilder.withArgName("automated").create("automated");
    options.addOption(automated);

    return options;
}

From source file:ape.NetworkDropPacketsCommand.java

/**
 * The constructor for this command simply creates its Option object (used by
 * the CLI parser)/*from w  ww .  ja v a2  s .  co  m*/
 */
public NetworkDropPacketsCommand() {
    option = OptionBuilder.withArgName("percentage> <duration").hasArgs(2).withValueSeparator().withDescription(
            "Drops a specified percentage of all inbound network packets for a duration specified in seconds.")
            .withLongOpt("network-drop").create("p");
}

From source file:ape.KillNodeCommand.java

/**
 * The constructor for this command simply creates its Option object (used by
 * the CLI parser)/*from  w w  w. j  a v a 2s .  c o m*/
 */
public KillNodeCommand() {
    option = OptionBuilder.withArgName("nodetype").hasArgs(1).withValueSeparator()
            .withDescription("Kills a datanode, tasktracker, jobtracker, or namenode.").withLongOpt("kill-node")
            .create("k");
}

From source file:com.amazonaws.services.dynamodbv2.online.index.ViolationDetector.java

public static void main(String[] args) {
    CommandLine commandLine;//from   w  w  w. j  a v  a 2  s.c  om
    org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();
    CommandLineParser parser = new GnuParser();
    HelpFormatter formatter = new HelpFormatter();

    Option optionHelp = new Option("h", "help", false, "Help and usage information");

    OptionBuilder.withArgName("keep/delete");
    OptionBuilder.withLongOpt("detect");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Detect violations on given table. " + "\nwith 'keep', violations will be kept and recorded;"
                    + "\nwith 'delete', violations will be deleted and recorded.");
    Option optionDetection = OptionBuilder.create("t");

    OptionBuilder.withArgName("update/delete");
    OptionBuilder.withLongOpt("correct");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Correct violations based on records on correction input file."
            + "\nwith 'delete', records on input file will be deleted from the table;"
            + "\nwith 'update', records on input file will be updated to the table.");
    Option optionCorrection = OptionBuilder.create("c");

    OptionBuilder.withArgName("configFilePath");
    OptionBuilder.withLongOpt("configFilePath");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Path of the config file. \nThis option is required for both detection and correction.");
    Option optionConfigFilePath = OptionBuilder.create("p");

    options.addOption(optionConfigFilePath);
    options.addOption(optionDetection);
    options.addOption(optionCorrection);
    options.addOption(optionHelp);

    try {
        ViolationDetector detector = new ViolationDetector();
        commandLine = parser.parse(options, args);

        /** Violation detection */
        if (commandLine.hasOption("t")) {
            if (!commandLine.hasOption("p")) {
                logger.error("Config file path not provided. Exiting...");
                formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
                System.exit(1);
            }
            String configFilePath = commandLine.getOptionValue("p");
            detector.setConfigFile(configFilePath);

            String detectOption = commandLine.getOptionValue("t");
            if (detectOption.compareTo("delete") == 0) {
                confirmDelete();
                detector.initDetection();
                detector.violationDetection(true);
            } else if (detectOption.compareTo("keep") == 0) {
                detector.initDetection();
                detector.violationDetection(false);
            } else {
                String errMessage = "Invalid options " + detectOption + " for 't/detect'";
                logger.error(errMessage + ". Exiting...");
                formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
                System.exit(1);
            }
            return;
        }

        /** Violation correction */
        if (commandLine.hasOption("c")) {
            if (!commandLine.hasOption("p")) {
                logger.error("Config file path not provided. Exiting...");
                formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
                System.exit(1);
            }
            String configFilePath = commandLine.getOptionValue("p");
            detector.setConfigFile(configFilePath);

            String correctOption = commandLine.getOptionValue("c");
            if (correctOption.compareTo("delete") == 0) {
                confirmDelete();
                detector.initCorrection();
                detector.violationCorrection(true, false /* useConditionalUpdate */);
            } else if (correctOption.compareTo("update") == 0) {
                detector.initCorrection();
                boolean useConditionalUpdate = getUseConditionalUpdateOptionFromConsole();
                detector.violationCorrection(false, useConditionalUpdate);
            } else {
                String errMessage = "Invalid options " + correctOption + " for 'c/correct'";
                logger.error(errMessage + ". Exiting...");
                formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
                System.exit(1);
            }
            return;
        }

        /** Help information */
        if (commandLine.hasOption("h")) {
            formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
            return;
        }

        /** Error: print usage and exit */
        String errMessage = "Invalid options, check usage";
        logger.error(errMessage + ". Exiting...");
        formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
        System.exit(1);

    } catch (IllegalArgumentException iae) {
        logger.error("Exception!", iae);
        System.exit(1);
    } catch (ParseException e) {
        logger.error("Exception!", e);
        formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/);
        System.exit(1);
    }
}

From source file:is.merkor.statistics.cli.MerkorCommandLineOptions.java

private static void createArgumentOptions() {
    input = OptionBuilder.withArgName("input file or directory").hasArg()
            .withDescription("the input file or directory").create("input");
    output = OptionBuilder.withArgName("output file or directory").hasArg()
            .withDescription("the output file or directory").create("output");
    merge = OptionBuilder.withArgName("file to merge").hasArg().withDescription("file to merge")
            .create("merge");
    lmi = OptionBuilder.withArgName("file to compute lmi").hasArg().withDescription("file to compute lmi")
            .create("lmi");
    lmi2db = OptionBuilder.withArgName("create db insert statements from argument file").hasArg()
            .withDescription("create db insert statements from argument file").create("lmi2db");
    tablename = OptionBuilder.withArgName("db tablename").hasArg().withDescription("db tablename")
            .create("tablename");
    wordwindow = OptionBuilder.withArgName("input file or directory").hasArg()
            .withDescription("file or directory to compute word window cooccurrence statistics")
            .create("wordwindow");
    sim = OptionBuilder.withArgName("compute similarities using the argument sparse matrix directory").hasArg()
            .withDescription("compute similarities using the argument sparse matrix directory").create("sim");
    tosql = OptionBuilder.withArgName("sql output file").hasArg().withDescription("sql output file")
            .create("tosql");
    tocsv = OptionBuilder.withArgName("csv output file").hasArg().withDescription("csv output file")
            .create("tocsv");
    w1 = OptionBuilder.withArgName("word to compute similarities for").hasArg()
            .withDescription("word to compute similarities for").create("w1");
    w2 = OptionBuilder.withArgName("word to compute similarities for").hasArg()
            .withDescription("word to compute similarities for").create("w2");
    n = OptionBuilder.withArgName("number of similar words to compute").hasArg()
            .withDescription("number of similar words to compute").create("n");
    cbc = OptionBuilder.withArgName("matrix to cluster").hasArg().withDescription("matrix to cluster")
            .create("cbc");
    simlist = OptionBuilder.withArgName("similarity lists").hasArg()
            .withDescription("file containing similarity lists").create("simlist");
}

From source file:net.ninjacat.stubborn.Stubborn.java

@SuppressWarnings("AccessStaticViaInstance")
private static Options createOptions() {
    Option source = OptionBuilder.withArgName("path|jar").withLongOpt(Context.SOURCE).hasArgs().isRequired()
            .withDescription(//from www  .  j a v a  2  s  . c o m
                    "Source path. Might be folder on a file system or a jar-file. You can specify multiple sources")
            .create('s');
    Option output = OptionBuilder.withArgName("path|jar").withLongOpt(Context.OUTPUT).hasArg().isRequired()
            .withDescription("Folder for output. Transformed classes will be stored to this folder")
            .create('o');
    Option rules = OptionBuilder.withArgName("xml-file").withLongOpt(Context.TRANSFORM_RULES).hasArg()
            .withDescription(
                    "Transformation rules file. If not specified, then default-rules.xml in current directory will be used")
            .create('r');
    Option stripNonPublic = OptionBuilder.withLongOpt(Context.STRIP_NON_PUBLIC)
            .withDescription("Only stub public methods, non-public methods will be removed from output classes")
            .create('n');
    Option stripFields = OptionBuilder.withLongOpt(Context.STRIP_FIELDS)
            .withDescription("Remove field definitions from classes").create('m');
    Option stripFinals = OptionBuilder.withLongOpt(Context.STRIP_FINAL)
            .withDescription("Remove final modifier from methods and classes").create('f');
    Option generateInstances = OptionBuilder.withLongOpt(Context.GENERATE_INSTANCES)
            .withDescription("Generate return newInstance() for reference return types").create("g");
    Option targetVersion = OptionBuilder.withArgName("version").withLongOpt(Context.TARGET_VERSION)
            .withDescription("Generate class files with specified target Java version").hasOptionalArg()
            .withType(Integer.class).create('t');
    Option verbose = OptionBuilder.withArgName("level").withLongOpt(Context.VERBOSE)
            .withDescription("Provide more output (-v 2 for even more output)").hasOptionalArg()
            .withType(Integer.class).create('v');
    Option ignoreDupMatchers = OptionBuilder.withLongOpt(Context.IGNORE_DUPLICATE_MATCHERS)
            .withDescription("Ignore duplicate matchers, use first defined.").create('i');
    Option classPath = OptionBuilder.withLongOpt(Context.CLASSPATH).hasArg()
            .withDescription("Additional classpath to be used during transformation").create("c");
    Option help = new Option("h", "help", false, "Show this help message");

    Options options = new Options();
    options.addOption(source);
    options.addOption(output);
    options.addOption(rules);
    options.addOption(stripNonPublic);
    options.addOption(stripFields);
    options.addOption(stripFinals);
    options.addOption(generateInstances);
    options.addOption(verbose);
    options.addOption(ignoreDupMatchers);
    options.addOption(classPath);
    options.addOption(help);
    options.addOption(targetVersion);

    return options;
}

From source file:ape.NetworkDisconnectCommand.java

/**
 * The constructor for this command simply creates its Option object (used by
 * the CLI parser)/*from   ww w . j a va  2 s  .c  om*/
 */
public NetworkDisconnectCommand() {
    option = OptionBuilder.withArgName("time").hasArgs(1).withValueSeparator().withDescription(
            "Disconnect the network for a certain period of time specified in the argument, and then resumes")
            .withLongOpt("network-disconnect").create("d");
}