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:com.comcast.oscar.cli.commands.HexDisplay.java

/**
 * Set option parameters for command Hexidecimal display
 * @return Option// ww  w .java  2  s . co m
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("t{oplevel}");
    OptionBuilder.hasArgs(1);
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("hex");
    OptionBuilder.withDescription(
            "Display the hex of the input file. Option t creates a newline at the start of every top level TLV (binary files only).");
    return OptionBuilder.create("x");
}

From source file:com.delcyon.capo.Configuration.java

@SuppressWarnings({ "unchecked", "static-access" })
public Configuration(String... programArgs) throws Exception {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilder = documentBuilderFactory.newDocumentBuilder();

    options = new Options();
    // the enum this is a little complicated, but it gives us a nice
    // centralized place to put all of the system parameters
    // and lets us iterate of the list of options and preferences
    PREFERENCE[] preferences = PREFERENCE.values();
    for (PREFERENCE preference : preferences) {
        // not the most elegant, but there is no default constructor, but
        // the has arguments value is always there
        OptionBuilder optionBuilder = OptionBuilder.hasArg(preference.hasArgument);
        if (preference.hasArgument == true) {
            String[] argNames = preference.arguments;
            for (String argName : argNames) {
                optionBuilder = optionBuilder.withArgName(argName);
            }/* w  w w  . j  a v a 2  s. co m*/
        }

        optionBuilder = optionBuilder.withDescription(preference.getDescription());
        optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
        options.addOption(optionBuilder.create(preference.getOption()));

        preferenceHashMap.put(preference.toString(), preference);
    }

    //add dynamic options

    Set<String> preferenceProvidersSet = CapoApplication.getAnnotationMap()
            .get(PreferenceProvider.class.getCanonicalName());
    if (preferenceProvidersSet != null) {
        for (String className : preferenceProvidersSet) {
            Class preferenceClass = Class.forName(className).getAnnotation(PreferenceProvider.class)
                    .preferences();
            if (preferenceClass.isEnum()) {
                Object[] enumObjects = preferenceClass.getEnumConstants();
                for (Object enumObject : enumObjects) {

                    Preference preference = (Preference) enumObject;
                    //filter out any preferences that don't belong on this server or client.
                    if (preference.getLocation() != Location.BOTH) {
                        if (CapoApplication.isServer() == true && preference.getLocation() == Location.CLIENT) {
                            continue;
                        } else if (CapoApplication.isServer() == false
                                && preference.getLocation() == Location.SERVER) {
                            continue;
                        }
                    }
                    preferenceHashMap.put(preference.toString(), preference);
                    boolean hasArgument = false;
                    if (preference.getArguments() == null || preference.getArguments().length == 0) {
                        hasArgument = false;
                    } else {
                        hasArgument = true;
                    }

                    OptionBuilder optionBuilder = OptionBuilder.hasArg(hasArgument);
                    if (hasArgument == true) {
                        String[] argNames = preference.getArguments();
                        for (String argName : argNames) {
                            optionBuilder = optionBuilder.withArgName(argName);
                        }
                    }

                    optionBuilder = optionBuilder.withDescription(preference.getDescription());
                    optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
                    options.addOption(optionBuilder.create(preference.getOption()));
                }

            }
        }
    }

    // create parser
    CommandLineParser commandLineParser = new GnuParser();
    this.commandLine = commandLineParser.parse(options, programArgs);

    Preferences systemPreferences = Preferences
            .systemNodeForPackage(CapoApplication.getApplication().getClass());
    String capoDirString = null;
    while (true) {
        capoDirString = systemPreferences.get(PREFERENCE.CAPO_DIR.longOption, null);
        if (capoDirString == null) {

            systemPreferences.put(PREFERENCE.CAPO_DIR.longOption, PREFERENCE.CAPO_DIR.defaultValue);
            capoDirString = PREFERENCE.CAPO_DIR.defaultValue;
            try {
                systemPreferences.sync();
            } catch (BackingStoreException e) {
                //e.printStackTrace();            
                if (systemPreferences.isUserNode() == false) {
                    System.err.println("Problem with System preferences, trying user's");
                    systemPreferences = Preferences
                            .userNodeForPackage(CapoApplication.getApplication().getClass());
                    continue;
                } else //just bail out
                {
                    throw e;
                }

            }
        }
        break;
    }

    disableAutoSync = hasOption(PREFERENCE.DISABLE_CONFIG_AUTOSYNC);

    File capoDirFile = new File(capoDirString);
    if (capoDirFile.exists() == false) {
        if (disableAutoSync == false) {
            capoDirFile.mkdirs();
        }
    }
    File configDir = new File(capoDirFile, PREFERENCE.CONFIG_DIR.defaultValue);
    if (configDir.exists() == false) {
        if (disableAutoSync == false) {
            configDir.mkdirs();
        }
    }

    if (disableAutoSync == false) {
        capoConfigFile = new File(configDir, CONFIG_FILENAME);
        if (capoConfigFile.exists() == false) {

            Document configDocument = CapoApplication.getDefaultDocument("config.xml");

            FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream));
            configFileOutputStream.close();
        }

        configDocument = documentBuilder.parse(capoConfigFile);
    } else //going memory only, because of disabled auto sync
    {
        configDocument = CapoApplication.getDefaultDocument("config.xml");
    }
    if (configDocument instanceof CDocument) {
        ((CDocument) configDocument).setSilenceEvents(true);
    }
    loadPreferences();
    preferenceValueHashMap.put(PREFERENCE.CAPO_DIR.longOption, capoDirString);
    //print out preferences
    //this also has the effect of persisting all of the default values if a values doesn't already exist
    for (PREFERENCE preference : preferences) {
        if (getValue(preference) != null) {
            CapoApplication.logger.log(Level.CONFIG, preference.longOption + "='" + getValue(preference) + "'");
        }
    }

    CapoApplication.logger.setLevel(Level.parse(getValue(PREFERENCE.LOGGING_LEVEL)));
}

From source file:com.denimgroup.threadfix.cli.CommandLineParser.java

@SuppressWarnings("static-access")
public static final Options getOptions() {
    Options options = new Options();

    Option teams = OptionBuilder.withLongOpt("teams")
            .withDescription("Fetches a list of ThreadFix teams and applications.").create("t");
    options.addOption(teams);/*w w w  . j  a v  a2s . c  o m*/
    options.addOption(new Option("help", "Print this message"));

    Option set = OptionBuilder.withArgName("property> <value").withValueSeparator(' ').hasArgs(2)
            .withLongOpt("set")
            .withDescription("Set either the url (ThreadFix base url) or key (ThreadFix API key) properties")
            .create("s");
    options.addOption(set);

    Option createTeam = OptionBuilder.withArgName("name").hasArg().withLongOpt("create-team")
            .withDescription("Creates a ThreadFix team and returns its JSON.").create("ct");
    options.addOption(createTeam);

    Option createApp = OptionBuilder.withArgName("teamId> <name> <url").withValueSeparator(' ').hasArgs(3)
            .withLongOpt("create-app").withDescription("Creates a ThreadFix application and returns its JSON.")
            .create("ca");
    options.addOption(createApp);

    Option createWaf = OptionBuilder.withArgName("name> <wafTypeName").withValueSeparator(' ').hasArgs(2)
            .withLongOpt("create-waf").withDescription("Creates a ThreadFix WAF and returns its JSON.")
            .create("cw");
    options.addOption(createWaf);

    Option searchTeam = OptionBuilder.withArgName("property> <value").withValueSeparator(' ').hasArgs(2)
            .withLongOpt("search-team").withDescription("Searches for a ThreadFix team and returns its JSON.")
            .create("st");
    options.addOption(searchTeam);

    Option searchWaf = OptionBuilder.withArgName("property> <value").withValueSeparator(' ').hasArgs(2)
            .withLongOpt("search-waf").withDescription("Searches for a ThreadFix WAF and returns its JSON.")
            .create("sw");
    options.addOption(searchWaf);

    Option searchApp = OptionBuilder.withArgName("property> <value1> <value2").withValueSeparator(' ')
            .hasArgs(3).withLongOpt("search-app")
            .withDescription("Searches for a ThreadFix application and returns its JSON.").create("sa");
    options.addOption(searchApp);

    Option upload = OptionBuilder.withArgName("appId> <file").withValueSeparator(' ').hasArgs(2)
            .withLongOpt("upload").withDescription("Uploads a scan to the specified application.").create("u");
    options.addOption(upload);

    Option getRules = OptionBuilder.withArgName("wafId").hasArg().withLongOpt("rules")
            .withDescription("Gets WAF Rules and returns its JSON.").create("r");
    options.addOption(getRules);

    return options;
}

From source file:de.haber.xmind2latex.cli.CliOptionBuilder.java

@SuppressWarnings("static-access")
/**/*w  w  w  .  ja  v  a  2s .  c  o  m*/
 * 
 * @return the CLI options for the XMindToLatex exporter.
 */
protected static Options getOptions() {
    Options o = new Options();

    o.addOption(OptionBuilder.withArgName("input file").withLongOpt("input")
            .withDescription("Required input file name.").hasArg(true).isRequired(false)
            .withType(PatternOptionBuilder.FILE_VALUE).create(INPUT));
    o.addOption(OptionBuilder.withArgName("force").withLongOpt("force")
            .withDescription("Force overwrite existing files (optional).").hasArg(false).isRequired(false)
            .create(FORCE));
    o.addOption(OptionBuilder.withArgName("output file").withLongOpt("output")
            .withDescription("Output file name (optional). Default output file is \"<input file>.tex.\"")
            .hasArg().isRequired(false).withType(PatternOptionBuilder.FILE_VALUE).create(OUTPUT));
    o.addOption(OptionBuilder.withArgName("template level").withLongOpt("template-level")
            .withDescription("Maximal level for template usage.").hasArg().isRequired(false)
            .withType(PatternOptionBuilder.NUMBER_VALUE).create(TEMPLATE_LEVEL));
    o.addOption(OptionBuilder.withArgName("help").withLongOpt("help")
            .withDescription("Prints this help message.").hasArg(false).isRequired(false).create(HELP));
    o.addOption(OptionBuilder.withArgName("level> <start> <end").withLongOpt("env").hasArgs(3)
            .withDescription("Sets the start and end environment templates for the given level (optional). "
                    + "Templates must be either loadable from the classpath with the given full qualified name (no file extension, "
                    + "directories separated by a '.', or as a file (with '.ftl' extension, directories separated by a path separator).")
            .isRequired(false).create(ENVIRONMENT));
    o.addOption(OptionBuilder.withArgName("level> <template").withLongOpt("level-template")
            .withValueSeparator(' ')
            .withDescription("Sets the template that is to be used for the given level (optional). "
                    + "Templates must be either loadable from the classpath with the given full qualified name (no file extension, "
                    + "directories separated by a '.', or as a file (with '.ftl' extension, directories separated by a path separator).")
            .hasArgs(2).isRequired(false).create(LEVEL));
    o.addOption(OptionBuilder.withArgName("version").withLongOpt("version")
            .withDescription("Prints the version.").hasArg(false).isRequired(false).create(VERSION));
    return o;
}

From source file:backtype.storm.command.gray_upgrade.java

private static Options buildGeneralOptions(Options opts) {
    Options r = new Options();

    for (Object o : opts.getOptions())
        r.addOption((Option) o);//  w w w.j a  v a 2  s.  co m

    Option workerNum = OptionBuilder.withArgName("worker num per batch").hasArg()
            .withDescription("number of workers to upgrade").create("n");
    r.addOption(workerNum);

    Option comp = OptionBuilder.withArgName("component to upgrade").hasArg()
            .withDescription("component id to upgrade, note that only one component is allowed at a time")
            .create("p");
    r.addOption(comp);

    Option workers = OptionBuilder.withArgName("workers to upgrade").hasArg()
            .withDescription("workers to upgrade, in the format: host1:port1,host2:port2,...").create("w");
    r.addOption(workers);

    return r;
}

From source file:backtype.storm.command.update_topology.java

private static Options buildGeneralOptions(Options opts) {
    Options r = new Options();

    for (Object o : opts.getOptions())
        r.addOption((Option) o);/*from  w  ww.j  a v  a2s.  c  o  m*/

    Option jar = OptionBuilder.withArgName("path").hasArg()
            .withDescription("comma  jar of the submitted topology").create("jar");
    r.addOption(jar);

    Option conf = OptionBuilder.withArgName("configuration file").hasArg()
            .withDescription("an application configuration file").create("conf");
    r.addOption(conf);
    return r;
}

From source file:com.example.geomesa.authorizations.SetupUtil.java

/**
 * Creates a common set of command-line options for the parser.  Each option
 * is described separately.//w  ww.  j a v a  2s.  c  om
 */
static Options getGeomesaDataStoreOptions() {
    Options options = new Options();

    Option instanceIdOpt = OptionBuilder.withArgName(INSTANCE_ID).hasArg().isRequired()
            .withDescription("the ID (name) of the Accumulo instance, e.g:  mycloud").create(INSTANCE_ID);
    options.addOption(instanceIdOpt);

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

    Option userOpt = OptionBuilder.withArgName(USER).hasArg().isRequired()
            .withDescription("the Accumulo user that will own the connection, e.g.:  root").create(USER);
    options.addOption(userOpt);

    Option passwordOpt = OptionBuilder.withArgName(PASSWORD).hasArg().isRequired()
            .withDescription("the password for the Accumulo user that will own the connection, e.g.:  toor")
            .create(PASSWORD);
    options.addOption(passwordOpt);

    Option authsOpt = OptionBuilder.withArgName(AUTHS).hasArg().withDescription(
            "the list of comma-separated Accumulo authorizations that will be used for data read by this Accumulo user; note that this is NOT the list of low-level database permissions such as 'Table.READ', but more a series of text tokens that decorate cell data, e.g.:  Accounting,Purchasing,Testing")
            .create(AUTHS);
    options.addOption(authsOpt);

    Option tableNameOpt = OptionBuilder.withArgName(TABLE_NAME).hasArg().isRequired().withDescription(
            "the name of the Accumulo table to use -- or create, if it does not already exist -- to contain the new data")
            .create(TABLE_NAME);
    options.addOption(tableNameOpt);

    options.addOption(OptionBuilder.withArgName(FEATURE_NAME).hasArg().isRequired()
            .withDescription("the FeatureTypeName used to store the GDELT data, e.g.:  gdelt")
            .create(FEATURE_NAME));

    options.addOption(OptionBuilder.withArgName(VISIBILITIES).hasArg()
            .withDescription("the visibilities applied to the GDELT data, e.g.:  user").create(VISIBILITIES));

    return options;
}

From source file:com.consol.citrus.CitrusCliOptions.java

/**
 * Default constructor.//ww  w. j  a  va2  s.c o m
 */
@SuppressWarnings("static-access")
public CitrusCliOptions() {

    this.addOption(new Option("help", "print usage help"));

    this.addOption(OptionBuilder.withArgName("suitename").hasArg()
            .withDescription("list of testsuites (seperated by blanks) that should run").isRequired(false)
            .create("suitename"));

    this.addOption(OptionBuilder.withArgName("test").hasArgs()
            .withDescription("list of test (seperated by blanks) that should run").isRequired(false)
            .create("test"));

    this.addOption(OptionBuilder.withArgName("testdir").hasArg()
            .withDescription("directory to look for test files").isRequired(false).create("testdir"));

    this.addOption(OptionBuilder.withArgName("package").hasArgs()
            .withDescription("executes all tests in a package").isRequired(false).create("package"));
}

From source file:com.example.geomesa.kafka08.KafkaLoadTester.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);/*  www  . j a  va2s.  com*/

    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 partitions = OptionBuilder.withArgName(PARTITIONS).hasArg()
            .withDescription("Number of partitions to use in Kafka topics").create(PARTITIONS);
    options.addOption(partitions);

    Option replication = OptionBuilder.withArgName(REPLICATION).hasArg()
            .withDescription("Replication factor to use in Kafka topics").create(REPLICATION);
    options.addOption(replication);

    Option load = OptionBuilder.withArgName(LOAD).hasArg().withDescription("Number of entities to simulate.")
            .create(LOAD);
    options.addOption(load);

    Option visibility = OptionBuilder.withArgName(VISIBILITY).hasArg()
            .withDescription("Visibilities to set on each feature created").create(VISIBILITY);
    options.addOption(visibility);

    return options;
}

From source file:fr.smartcontext.yatte.context.cli.DefaultOptionsProvider.java

/** 
 * {@inheritDoc}/*from  w  w w . j  a v  a 2 s  . c o  m*/
 * @see fr.smartcontext.yatte.context.cli.CLIOptionsProvider#getOptions()
 */
@Override
public Options getOptions() {
    Options options = new Options();
    OptionBuilder.withLongOpt(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_ARGUMENT_NAME);
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_NAME));

    OptionBuilder.withLongOpt(ApplicationParametersConstants.OUTPUT_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.OUTPUT_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.OUTPUT_OPTION_ARGUMENT_NAME);
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.OUTPUT_OPTION_NAME));

    OptionBuilder.withLongOpt(ApplicationParametersConstants.TEMPLATE_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.TEMPLATE_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.TEMPLATE_OPTION_ARGUMENT_NAME);
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.TEMPLATE_OPTION_NAME));

    return options;
}