Example usage for org.apache.commons.cli OptionGroup addOption

List of usage examples for org.apache.commons.cli OptionGroup addOption

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionGroup addOption.

Prototype

public OptionGroup addOption(Option option) 

Source Link

Document

Add the specified Option to this group.

Usage

From source file:net.nharyes.drivecopy.Main.java

private void composeOptions() {

    // file option
    Option file = OptionBuilder.create('f');
    file.setLongOpt("file");
    file.setArgs(1);//from  w  ww .ja va 2  s  .  com
    file.setArgName("path");
    file.setDescription("where path is the file to upload/download/replace.");

    // directory option
    Option directory = OptionBuilder.create('d');
    directory.setLongOpt("directory");
    directory.setArgs(1);
    directory.setArgName("path");
    directory.setDescription(
            "where path is the local directory to upload/download/replace (it will be archived into a single remote file).");

    // file and directory group
    OptionGroup group = new OptionGroup();
    group.addOption(file);
    group.addOption(directory);
    group.setRequired(true);
    options.addOptionGroup(group);

    // compression level option
    Option level = OptionBuilder.create('l');
    level.setLongOpt("level");
    level.setArgs(1);
    level.setArgName("num");
    level.setOptionalArg(true);
    level.setType(Integer.class);
    level.setDescription(
            "where num is the compression level from 0 to 9. Used when uploading/replacing directories. The default value is 0.");
    options.addOption(level);

    // delete option
    Option delete = OptionBuilder.create('D');
    delete.setLongOpt("delete");
    delete.setOptionalArg(true);
    delete.setType(Boolean.class);
    delete.setDescription("delete local file/directory after remote entry uploaded/replaced.");
    options.addOption(delete);

    // log option
    Option log = OptionBuilder.create('L');
    log.setLongOpt("log");
    log.setArgs(1);
    log.setArgName("file");
    log.setType(String.class);
    log.setDescription("where file is the log file to write");
    options.addOption(log);

    // MIME type option
    Option mimeType = OptionBuilder.create('m');
    mimeType.setLongOpt("mimetype");
    mimeType.setArgs(1);
    mimeType.setArgName("type");
    mimeType.setType(String.class);
    mimeType.setDescription(
            "where type is the MIME type string to set for the remote entry. The default values are 'application/octet-stream' for files and 'application/zip' for compressed directories.");
    options.addOption(mimeType);

    // skip revision option
    Option skipRevision = OptionBuilder.create('s');
    skipRevision.setLongOpt("skiprevision");
    skipRevision.setOptionalArg(true);
    skipRevision.setType(Boolean.class);
    skipRevision.setDescription("do not create a new revision when replacing remote entry.");
    options.addOption(skipRevision);

    // check MD5 option
    Option checkMd5 = OptionBuilder.create('c');
    checkMd5.setLongOpt("checkmd5");
    checkMd5.setOptionalArg(true);
    checkMd5.setType(Boolean.class);
    checkMd5.setDescription(
            "compare uploaded/downloaded local file MD5 summary with the one of the remote entry.");
    options.addOption(checkMd5);

    // check force creation option
    Option forceCreation = OptionBuilder.create('F');
    forceCreation.setLongOpt("force");
    forceCreation.setOptionalArg(true);
    forceCreation.setType(Boolean.class);
    forceCreation.setDescription(
            "forces the creation of the remote entry when replace is selected and the entry doesn't exist.");
    options.addOption(forceCreation);

    // settings file option
    Option settings = OptionBuilder.create('C');
    settings.setLongOpt("configuration");
    settings.setArgs(1);
    settings.setArgName("path");
    settings.setType(String.class);
    settings.setDescription(String.format(
            "where path is the path of the configuration file. The default value is '%s' in the same directory.",
            CONFIGURATION_FILE));
    options.addOption(settings);

    // create folders tree option
    Option tree = OptionBuilder.create('t');
    tree.setLongOpt("tree");
    tree.setOptionalArg(true);
    tree.setType(Boolean.class);
    tree.setDescription("create remote folders tree if one or more remote folders are not found.");
    options.addOption(tree);
}

From source file:com.github.lindenb.jvarkit.util.command.CommandFactory.java

protected void fillOptions(final Options opts) {
    final OptionGroup g = new OptionGroup();
    g.addOption(createHelpOption());
    g.addOption(createVersionOption());//from   w w w  .j av a 2s. co  m
    g.addOption(Option.builder("proxy").required(false).longOpt("proxy").hasArg(true).argName("HOST:PORT")
            .desc("set the http and the https proxy.").build());
    opts.addOptionGroup(g);
}

From source file:esg.node.security.shell.cmds.ESGFassociate.java

public void doInitOptions() {
    getOptions().addOption("n", "no_prompt", false, "suppress request confirmation before making associations");

    Option username = OptionBuilder.withArgName("username").hasArg(true)
            .withDescription("user name you wish to associate").withLongOpt("username").isRequired(true)
            .create("u");
    getOptions().addOption(username);//from  www.j ava 2s .  c  o m

    Option groupname = OptionBuilder.withArgName("groupname").hasArg(true)
            .withDescription("group name you wish to associate").withLongOpt("groupname").isRequired(false)
            .create("g");
    getOptions().addOption(groupname);

    Option rolename = OptionBuilder.withArgName("rolename").hasArg(true)
            .withDescription("role name you wish to associate").withLongOpt("rolename").isRequired(false)
            .create("r");
    getOptions().addOption(rolename);

    Option add = new Option("add", false, "creates a permission entry from the given (user,group,role) tuple");
    Option remove = new Option("remove", false, "removes the specified group and role from specified user");
    Option removeGroupFromUser = new Option("remove_group_from_user", false,
            "removes the specified group from specified user");
    Option removeRoleFromUser = new Option("remove_role_from_user", false,
            "removes the specified role from specified user");
    Option removeAll = new Option("remove_all", false, "removes all group and roles associated with user");

    OptionGroup directiveOptionGroup = new OptionGroup();
    directiveOptionGroup.addOption(add);
    directiveOptionGroup.addOption(remove);
    directiveOptionGroup.addOption(removeGroupFromUser);
    directiveOptionGroup.addOption(removeRoleFromUser);
    directiveOptionGroup.addOption(removeAll);
    getOptions().addOptionGroup(directiveOptionGroup);
}

From source file:io.warp10.worf.WorfCLI.java

public WorfCLI() {
    options.addOption(new Option(KEYSTORE, "keystore", true,
            "configuration file for generating tokens inside templates"));
    options.addOption(new Option(OUTPUT, "output", true, "output configuration destination file"));
    options.addOption(new Option(TOKEN, "tokens", false, "generate read/write tokens"));
    options.addOption(new Option("f", "format", false, "output tokens format. (default JSON)"));

    OptionGroup groupProducerUID = new OptionGroup();
    groupProducerUID.addOption(new Option(UUIDGEN_PRODUCER, "producer-uuid-gen", false,
            "creates a new universally unique identifier for the producer"));
    groupProducerUID.addOption(new Option(P_UUID, "producer-uuid", true, "data producer uuid"));

    OptionGroup groupOwnerUID = new OptionGroup();
    groupOwnerUID.addOption(new Option(UUIDGEN_OWNER, "owner-uuid-gen", false,
            "creates a new universally unique identifier for the owner"));
    groupOwnerUID/*from w  ww . jav a  2  s  .  co  m*/
            .addOption(new Option(O_UUID, "owner-uuid", true, "data owner uuid (producer uuid by default)"));

    options.addOptionGroup(groupProducerUID);
    options.addOptionGroup(groupOwnerUID);

    options.addOption(new Option(APPNAME, "app-name", true,
            "token application name. Used by token option or @warp:writeToken@ template"));
    options.addOption(new Option(TTL, "ttl", true,
            "token time to live (ms). Used by token option or @warp:writeToken@ template"));

    options.addOption(HELP, "help", false, "show help.");
    options.addOption(VERBOSE, "verbose", false, "Verbose mode");
    options.addOption(VERSION, "version", false, "Print version number and return");
    options.addOption(INTERACTIVE, "interactive", false, "Interactive mode, all other options are ignored");
}

From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java

/**
 * Setup command line options/*from   w w  w .ja  va 2  s . c om*/
 */
@SuppressWarnings("static-access")
private void setupCommandLine() {
    // --- Options on the command line ---
    Option help = OptionBuilder.withLongOpt(HELP).withDescription("Displays this message").create(_HELP);

    // Mutually excluding options
    OptionGroup optionGroup = new OptionGroup();
    check = OptionBuilder.withLongOpt(CHECK).hasArgs(0).withDescription("Checks key password inside a keystore")
            .create(_CHECK);

    optionGroup.addOption(check);
    optionGroup.setRequired(true); // At least 1 command required

    // --- Options replacing parameters from security.properties ---
    Option keystoreLocation = OptionBuilder.withLongOpt(KEYSTORE_LOCATION).withArgName("filename").hasArg()
            .withDescription("Location of the keystore file").isRequired().create(_KEYSTORE_LOCATION);
    Option keyAlias = OptionBuilder.withLongOpt(KEY_ALIAS).withArgName("key alias").hasArg().isRequired()
            .withDescription("Alias for the key").create(_KEY_ALIAS);
    Option keyType = OptionBuilder.withLongOpt(KEY_TYPE).withArgName("key type").hasArg().isRequired()
            .withDescription(MessageFormat.format("Type of key: {0}", KEYSTORE_TYPE.getListValues("|")))
            .create(_KEY_TYPE);

    Option keystorePassword = OptionBuilder.withLongOpt(KEYSTORE_PASSWORD).withArgName("password").hasArg()
            .withDescription("Password for the keystore file").create(_KEYSTORE_PASSWORD);
    Option keyPassword = OptionBuilder.withLongOpt(KEY_PASSWORD).withArgName("key password").hasArg()
            .withDescription("Password for the key").create(_KEY_PASSWORD);

    // --- Add options to the list ---
    // --- Help
    this.helpOptions.addOption(help);

    // --- Program command line options
    this.options.addOptionGroup(optionGroup);
    this.options.addOption(help);
    this.options.addOption(keystoreLocation);
    this.options.addOption(keyAlias);
    this.options.addOption(keyType);
    this.options.addOption(keystorePassword);
    this.options.addOption(keyPassword);
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

private Options initialize(String[] args) {
    OptionGroup group = new OptionGroup();

    Option helpOpt = new Option(null, "help", false, "this message");
    helpOpt.setArgs(2);//from www .j av  a2  s.c om
    helpOpt.setValueSeparator(',');
    group.addOption(helpOpt);

    Option opt = new Option("sh", "shutdown", true, "the service to shut down");
    opt.setArgs(2);
    opt.setValueSeparator(',');
    group.addOption(opt);

    Option updateOpt = new Option(null, "dbupdate", false, "the database update parameters");
    updateOpt.setArgs(3);
    updateOpt.setValueSeparator(',');
    group.addOption(updateOpt);

    Option unbindOpt = new Option(null, "unbind", true,
            "the unbind option to be used ONLY if the service cannot be shut down gracefully");
    unbindOpt.setArgs(2);
    unbindOpt.setValueSeparator(',');
    group.addOption(unbindOpt);
    addOptions(group);

    Options options = new Options();
    options.addOptionGroup(group);
    return options;
}

From source file:fr.iphc.grid.jobmanager.JobManager.java

@SuppressWarnings("static-access")
protected Options createOptions() {
    Options opt = new Options();

    // command/* w  ww  .j av a  2  s.  co m*/
    opt.addOption(OptionBuilder.withDescription("Display this help and exit").withLongOpt(LONGOPT_HELP)
            .create(OPT_HELP));

    // optional arguments
    opt.addOption(OptionBuilder.withDescription("file with cream URL [IPHC]").hasArg()
            .withLongOpt(LONGOPT_QUEUE).withArgName("queue").create(OPT_QUEUE));

    opt.addOption(OptionBuilder
            .withDescription("generate the job description in the targeted grid language "
                    + "and exit (do not submit the job)")
            .withLongOpt(LONGOPT_DESCRIPTION).create(OPT_DESCRIPTION));

    opt.addOption(OptionBuilder.withDescription("File List of Bad Ce elminate from the Ce List[IPHC]").hasArg()
            .withLongOpt(LONGOPT_BAD).create(OPT_BAD));

    opt.addOption(OptionBuilder
            .withDescription("Time -> END Program in minutes/hour (Default 10H) Value: mM hH  [IPHC]").hasArg()
            .withLongOpt(LONGOPT_END).create(OPT_END));

    opt.addOption(OptionBuilder
            .withDescription("Duration Run -Thread in minutes/hour (Default 1H) Value: mM hH  [IPHC]").hasArg()
            .withLongOpt(LONGOPT_RUN).create(OPT_RUN));

    opt.addOption(
            OptionBuilder.withDescription("Time queue wating in CE/queue in minutes (Default 15 mn) [IPHC]")
                    .hasArg().withLongOpt(LONGOPT_WAIT).create(OPT_WAIT));

    opt.addOption(OptionBuilder.withDescription("Threshold display full log in log file[IPHC]").hasArg()
            .withLongOpt(LONGOPT_LOGDISPLAY).create(OPT_LOGDISPLAY));

    opt.addOption(
            OptionBuilder.withDescription("Define working directory for monitoring file (default cwd) [IPHC]")
                    .hasArg().withLongOpt(LONGOPT_CWD).create(OPT_CWD));

    opt.addOption(OptionBuilder.withDescription("Setup xml file Global paramters (default setup) [IPHC]")
            .hasArg().withLongOpt(LONGOPT_SETUP).create(OPT_SETUP));

    opt.addOption(OptionBuilder.withDescription("Disable Optimize Timeout Run Average execution time[IPHC]")
            .withLongOpt(LONGOPT_OPTIMIZETIMEOUTRUN).create(OPT_OPTIMIZETIMEOUTRUN));

    // required arguments group jdl file | list of jdl
    OptionGroup reqGroup = new OptionGroup();
    reqGroup.addOption(OptionBuilder.withDescription("read job description from file <path> [IPHC]").hasArg()
            .withLongOpt(LONGOPT_JOB).withArgName("file").create(OPT_JOB));
    reqGroup.addOption(OptionBuilder.withDescription("read file include jdl file [IPHC]").hasArg()
            .withLongOpt(LONGOPT_FILEJOB).withArgName("list").create(OPT_FILEJOB));
    reqGroup.setRequired(true);
    opt.addOptionGroup(reqGroup);

    // optional group
    OptionGroup optGroup = new OptionGroup();
    optGroup.addOption(OptionBuilder
            .withDescription(
                    "print the job identifier as soon as it is submitted, " + "and wait for it to be finished")
            .withLongOpt(LONGOPT_JOBID).create(OPT_JOBID));

    optGroup.setRequired(false);
    opt.addOptionGroup(optGroup);

    // job description
    opt.addOption(o("positional parameters for the command").hasArgs().create(JobDescription.ARGUMENTS));
    opt.addOption(o("SPMD job type and startup mechanism").hasArg().create(JobDescription.SPMDVARIATION));
    opt.addOption(
            o("total number of cpus requested for this job").hasArg().create(JobDescription.TOTALCPUCOUNT));
    opt.addOption(o("number of process instances to start").hasArg().create(JobDescription.NUMBEROFPROCESSES));
    opt.addOption(o("number of processes to start per host").hasArg().create(JobDescription.PROCESSESPERHOST));
    opt.addOption(
            o("expected number of threads per process").hasArg().create(JobDescription.THREADSPERPROCESS));
    opt.addOption(o("set of environment variables for the job").hasArgs().withValueSeparator()
            .create(JobDescription.ENVIRONMENT));
    opt.addOption(o("working directory for the job").hasArg().create(JobDescription.WORKINGDIRECTORY));
    opt.addOption(o("run the job in interactive mode").create(JobDescription.INTERACTIVE));
    opt.addOption(o("pathname of the standard input file").hasArg().create(JobDescription.INPUT));
    opt.addOption(o("pathname of the standard output file").hasArg().create(JobDescription.OUTPUT));
    opt.addOption(o("pathname of the standard error file").hasArg().create(JobDescription.ERROR));
    opt.addOption(o("a list of file transfer directives").hasArgs().create(JobDescription.FILETRANSFER));
    opt.addOption(o("defines if output files get removed after the job finishes").hasArg()
            .create(JobDescription.CLEANUP));
    opt.addOption(o("time at which a job should be scheduled").hasArg().create(JobDescription.JOBSTARTTIME));
    opt.addOption(o("hard limit for the total job runtime").hasArg().create(JobDescription.WALLTIMELIMIT));
    opt.addOption(o("estimated total number of CPU seconds which the job will require").hasArg()
            .create(JobDescription.TOTALCPUTIME));
    opt.addOption(o("estimated amount of memory the job requires").hasArg()
            .create(JobDescription.TOTALPHYSICALMEMORY));
    opt.addOption(o("compatible processor for job submission").hasArg().create(JobDescription.CPUARCHITECTURE));
    opt.addOption(o("compatible operating system for job submission").hasArg()
            .create(JobDescription.OPERATINGSYSTEMTYPE));
    opt.addOption(
            o("list of host names which are to be considered by the resource manager as candidate targets")
                    .hasArgs().create(JobDescription.CANDIDATEHOSTS));
    opt.addOption(o("name of a queue to place the job into").hasArg().create(JobDescription.QUEUE));
    opt.addOption(o("name of an account or project name").hasArg().create(JobDescription.JOBPROJECT));
    opt.addOption(o("set of endpoints describing where to report").hasArgs().create(JobDescription.JOBCONTACT));

    // returns
    return opt;
}

From source file:com.github.lindenb.jvarkit.util.command.Command.java

protected void fillOptions(final Options opts) {
    final OptionGroup g = new OptionGroup();
    g.addOption(createHelpOption());
    g.addOption(createVersionOption());//  w  w w  .  j a v a  2  s  .  c o m
    opts.addOptionGroup(g);
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Processes all command line parameters and returns a {@link CommandLine}
 * object, which holds all values included in the given {@link String}
 * array.//from   w  w w.ja v  a2  s.c om
 * 
 * @param args
 *            {@link CommandLine} parameters.
 * @return {@link CommandLine} object, which holds all necessary values.
 */
public static CommandLine processCommandLineOptions(String[] args) {

    // Creates a OptionHandler.
    String toolString = "java " + SchemaGraph2XMI.class.getName();
    String versionString = JGraLab.getInfo(false);

    OptionHandler oh = new OptionHandler(toolString, versionString);

    // Several Options are declared.
    Option output = new Option("o", "output", true, "(required): the output xmi file name");
    output.setRequired(true);
    output.setArgName("file");
    oh.addOption(output);

    Option schemaGraph = new Option("ig", "inputSchemaGraph", true,
            "(required or -i):if set, the schemaGraph is converted into a xmi.");
    schemaGraph.setRequired(false);
    schemaGraph.setArgs(0);
    output.setArgName("file");
    oh.addOption(schemaGraph);

    Option schema = new Option("i", "inputSchema", true,
            "(required or -ig): TG-file of the schema which should be converted into a xmi.");
    schema.setRequired(false);
    schema.setArgName("file");
    oh.addOption(schema);

    // either graph or schema has to be provided
    OptionGroup input = new OptionGroup();
    input.addOption(schemaGraph);
    input.addOption(schema);
    input.setRequired(true);
    oh.addOptionGroup(input);

    Option bidirectional = new Option("b", "bidirectional", false,
            "(optional): If set the EdgeClasses are created as bidirectional associations.");
    bidirectional.setRequired(false);
    oh.addOption(bidirectional);

    return oh.parse(args);
}

From source file:com.hp.mqm.clt.CliParser.java

public CliParser() {
    options.addOption("h", "help", false, "show this help");
    options.addOption("v", "version", false, "show version of this tool");

    options.addOption("i", "internal", false, "supplied XML files are in the API internal XML format");
    options.addOption("e", "skip-errors", false, "skip errors on the server side");
    options.addOption(Option.builder("o").longOpt("output-file")
            .desc("write output to file instead of pushing it to the server").hasArg().argName("FILE").build());
    options.addOption(Option.builder("c").longOpt("config-file").desc("configuration file location").hasArg()
            .argName("FILE").build());

    options.addOption(Option.builder("s").longOpt("server").desc("server URL with protocol and port").hasArg()
            .argName("URL:PORT").build());
    options.addOption(Option.builder("d").longOpt("shared-space").desc("server shared space to push to")
            .hasArg().argName("ID").type(Number.class).build());
    options.addOption(Option.builder("w").longOpt("workspace").desc("server workspace to push to").hasArg()
            .argName("ID").type(Number.class).build());

    options.addOption(//w  w  w.  j a v a2 s  .c  om
            Option.builder("u").longOpt("user").desc("server username").hasArg().argName("USERNAME").build());
    OptionGroup passGroup = new OptionGroup();
    passGroup.addOption(Option.builder("p").longOpt("password").desc("server password").hasArg()
            .argName("PASSWORD").optionalArg(true).build());
    passGroup.addOption(Option.builder().longOpt("password-file").desc("location of file with server password")
            .hasArg().argName("FILE").build());
    options.addOptionGroup(passGroup);

    options.addOption(
            Option.builder().longOpt("proxy-host").desc("proxy host").hasArg().argName("HOSTNAME").build());
    options.addOption(Option.builder().longOpt("proxy-port").desc("proxy port").hasArg().argName("PORT")
            .type(Number.class).build());
    options.addOption(
            Option.builder().longOpt("proxy-user").desc("proxy username").hasArg().argName("USERNAME").build());

    OptionGroup proxyPassGroup = new OptionGroup();
    proxyPassGroup.addOption(Option.builder().longOpt("proxy-password").desc("proxy password").hasArg()
            .argName("PASSWORD").optionalArg(true).build());
    proxyPassGroup.addOption(Option.builder().longOpt("proxy-password-file")
            .desc("location of file with proxy password").hasArg().argName("FILE").build());
    options.addOptionGroup(proxyPassGroup);

    options.addOption(
            Option.builder().longOpt("check-result").desc("check test result status after push").build());
    options.addOption(Option.builder().longOpt("check-result-timeout")
            .desc("timeout for test result push status retrieval").hasArg().argName("SEC").type(Number.class)
            .build());

    options.addOption(Option.builder("t").longOpt("tag").desc("assign tag to test result").hasArg()
            .argName("TYPE:VALUE").build());
    options.addOption(Option.builder("f").longOpt("field").desc("assign field tag to test result").hasArg()
            .argName("TYPE:VALUE").build());

    options.addOption(Option.builder("r").longOpt("release").desc("assign release to test result").hasArg()
            .argName("ID").type(Number.class).build());
    options.addOption(Option.builder("a").longOpt("product-area").desc("assign the test result to product area")
            .hasArg().argName("ID").type(Number.class).build());
    options.addOption(Option.builder("b").longOpt("backlog-item").desc("assign the test result to backlog item")
            .hasArg().argName("ID").type(Number.class).build());
    options.addOption(Option.builder().longOpt("started").desc("start time in milliseconds").hasArg()
            .argName("TIMESTAMP").type(Number.class).build());

    argsWithSingleOccurrence.addAll(Arrays.asList("o", "c", "s", "d", "w", "u", "p", "password-file", "r",
            "started", "check-status", "check-status-timeout", "proxy-host", "proxy-port", "proxy-user",
            "proxy-password", "proxy-password-file"));
    argsRestrictedForInternal.addAll(Arrays.asList("o", "t", "f", "r", "a", "b", "started"));
}