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:com.nokia.tools.vct.cli.CommandLineUtils.java

public static void initOptions(Options options) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();

    IExtension[] extensions = registry.getExtensionPoint(EXTENSION_NAMESPACE).getExtensions();
    for (IExtension extension : extensions) {
        for (IConfigurationElement element : extension.getConfigurationElements()) {
            if (ELEMENT_OPTION.equals(element.getName())) {
                Option option = makeOption(element);
                options.addOption(option);
            } else if (ELEMENT_OPTION_GROUP.equals(element.getName())) {
                OptionGroup optionGroup = new OptionGroup();
                boolean required = Boolean.TRUE.equals(element.getAttribute(OPTION_GROUP_ATTR_REQUIRED));
                optionGroup.setRequired(required);
                for (IConfigurationElement element2 : element.getChildren(ELEMENT_OPTION)) {
                    Option option = makeOption(element2);
                    optionGroup.addOption(option);
                }//from   ww w .  j  a v a  2 s. co m
                options.addOptionGroup(optionGroup);
            }
        }
    }
}

From source file:com.linkedin.helix.mock.storage.DummyProcess.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();//from  w w  w.ja  v a  2s.com

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option cmTypeOption = OptionBuilder.withLongOpt(helixManagerType)
            .withDescription("Provide cluster manager type (e.g. 'zk', 'static-file', or 'dynamic-file'")
            .create();
    cmTypeOption.setArgs(1);
    cmTypeOption.setRequired(true);
    cmTypeOption.setArgName("Clsuter manager type (e.g. 'zk', 'static-file', or 'dynamic-file') (Required)");

    // add an option group including either --zkSvr or --clusterViewFile
    Option fileOption = OptionBuilder.withLongOpt(clusterViewFile)
            .withDescription("Provide a cluster-view file for static-file based cluster manager").create();
    fileOption.setArgs(1);
    fileOption.setRequired(true);
    fileOption.setArgName("Cluster-view file (Required for static-file based cluster manager)");

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required for zk-based cluster manager)");

    //    Option rootNsOption = OptionBuilder.withLongOpt(rootNamespace)
    //        .withDescription("Provide root namespace for dynamic-file based cluster manager").create();
    //    rootNsOption.setArgs(1);
    //    rootNsOption.setRequired(true);
    //    rootNsOption.setArgName("Root namespace (Required for dynamic-file based cluster manager)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);
    optionGroup.addOption(fileOption);
    //    optionGroup.addOption(rootNsOption);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(transDelayOption);
    options.addOption(cmTypeOption);

    options.addOptionGroup(optionGroup);

    return options;
}

From source file:br.edu.ufcg.lsd.oursim.ui.CLI.java

public static Options prepareOptions() {

    // Para adicionar uma evento:
    // 1. Defina uma constante com a identificao da opo
    // 2. Cria a Option referente
    // 3. Opcionalmente defina o tipo do argumento, quantidade de parmetros
    // ou restries
    // 4. Adicione a Options
    Options options = new Options();

    Option availability = new Option(AVAILABILITY, "availability", true,
            "Arquivo com a caracterizao da disponibilidade para todos os recursos.");
    Option dedicatedResources = new Option(DEDICATED_RESOURCES, "dedicated", false,
            "Indica que os recursos so todos dedicados.");
    Option syntAvail = new Option(SYNTHETIC_AVAILABILITY, "synthetic_availability", true,
            "Disponibilidade dos recursos deve ser gerada sinteticamente.");
    Option syntAvailDur = new Option(SYNTHETIC_AVAILABILITY_DURATION, "synthetic_availability_duration", true,
            "At que momento gerar eventos de disponibilidade dos recursos.");
    Option workload = new Option(WORKLOAD, "workload", true,
            "Arquivo com o workload no format GWA (Grid Workload Archive).");
    Option utilization = new Option(UTILIZATION, "utilization", true,
            "Arquivo em que ser registrada a utilizao da grade.");
    Option workerEvents = new Option(WORKER_EVENTS, "worker_events", true,
            "Arquivo em que sero registrados os eventos de disponibilidade.");
    Option taskEvents = new Option(TASK_EVENTS, "task_events", true,
            "Arquivo em que ser registrados os eventos de envolvendo tasks.");
    Option workloadType = new Option(WORKLOAD_TYPE, "workload_type", true,
            "The type of workload to read the workload file.");
    Option machinesDescription = new Option(MACHINES_DESCRIPTION, "machinesdescription", true,
            "Descrio das mquinas presentes em cada peer.");
    Option speedOption = new Option(NODE_MIPS_RATING, "speed", true, "A velocidade de cada mquina.");
    Option scheduler = new Option(SCHEDULER, "scheduler", true, "Indica qual scheduler dever ser usado.");
    Option peersDescription = new Option(PEERS_DESCRIPTION, "peers_description", true,
            "Arquivo descrevendo os peers.");
    Option numResByPeer = new Option(NUM_RESOURCES_BY_PEER, "nresources", true,
            "O nmero de rplicas para cada task.");
    Option numPeers = new Option(NUM_PEERS, "npeers", true, "O nmero de peers do grid.");
    Option nofOption = new Option(NOF, "nof", false, "Utiliza a Rede de Favores (NoF).");
    Option erwOption = new Option(EXTRACT_REMOTE_WORKLOAD, "extract_remote_workload", true,
            "Extrai, para cada job, o subconjunto das tasks que rodaram em recursos remotos.");
    Option output = new Option(OUTPUT, "output", true,
            "O nome do arquivo em que o output da simulao ser gravado.");
    Option halt = new Option(HALT_SIMULATION, "halt", true,
            "O tempo em que a simulao deve parar incondicionalmente.");

    workload.setRequired(true);//  ww  w.  j  a v  a2s .com
    peersDescription.setRequired(true);
    output.setRequired(true);

    workload.setType(File.class);
    peersDescription.setType(File.class);
    machinesDescription.setType(File.class);
    availability.setType(File.class);
    utilization.setType(File.class);
    workerEvents.setType(File.class);
    taskEvents.setType(File.class);
    output.setType(File.class);
    erwOption.setType(File.class);
    numResByPeer.setType(Number.class);
    numPeers.setType(Number.class);
    speedOption.setType(Number.class);
    //      syntAvail.setType(Number.class);
    syntAvailDur.setType(Number.class);
    syntAvail.setType(String.class);
    halt.setType(Number.class);

    scheduler.setArgs(2);
    availability.setArgs(2);
    // syntAvail.setArgs(2);

    OptionGroup availGroup = new OptionGroup();
    availGroup.addOption(availability);
    availGroup.addOption(dedicatedResources);
    availGroup.addOption(syntAvail);

    options.addOptionGroup(availGroup);

    options.addOption(workload);
    options.addOption(workloadType);
    options.addOption(machinesDescription);
    options.addOption(scheduler);
    options.addOption(syntAvailDur);
    options.addOption(output);
    options.addOption(erwOption);
    options.addOption(numResByPeer);
    options.addOption(numPeers);
    options.addOption(peersDescription);
    options.addOption(speedOption);
    options.addOption(nofOption);
    options.addOption(utilization);
    options.addOption(workerEvents);
    options.addOption(taskEvents);
    options.addOption(halt);

    options.addOption(VERBOSE, "verbose", false, "Informa todos os eventos importantes.");
    options.addOption(HELP, false, "Comando de ajuda.");
    options.addOption(USAGE, false, "Instrues de uso.");

    return options;
}

From source file:ape.Main.java

/**
 * This method generates all the options, and stores them in opts
 *///from   w  ww  .  ja va2s  .  com
public static void createOptions() {
    //System.out.println("creating options ...");
    Options options = new Options();
    options.addOption("h", "help", false, "Displays this help menu");
    options.addOption("V", "version", false, "Displays the version number");
    options.addOption(OptionBuilder.withValueSeparator().withDescription("Turn on verbose mode")
            .withLongOpt("verbose").create("v"));

    // Adds all of the commands in the service loader to an OptionGroup so that they are all mutually exclusive
    OptionGroup apeCommands = new OptionGroup();
    Iterator<ApeCommand> iter = loader.iterator();
    while (iter.hasNext()) {
        ApeCommand ac = iter.next();
        apeCommands.addOption(ac.getOption());
        //System.out.println(ac.getOption());
    }
    options.addOptionGroup(apeCommands);

    // Makes the local and remote commands mutually exclusive
    OptionGroup remoteOrLocal = new OptionGroup();
    remoteOrLocal.addOption(OptionBuilder.withArgName("HostnameList").hasArgs().withValueSeparator()
            .withDescription("Run commands remotely").withLongOpt("remote").create("R"));
    remoteOrLocal.addOption(OptionBuilder.withArgName("Command").withValueSeparator()
            .withDescription("Run commands locally").withLongOpt("local").create("L"));
    options.addOptionGroup(remoteOrLocal);

    opts = options;
}

From source file:com.imgur.backup.SnapshotS3Util.java

/**
 * Returns the command-line options supported.
 * @return the command-line options/*www.  ja v a2s .  co m*/
 */
private static Options getOptions() {
    Option tableName = new Option("t", "table", true,
            "The table name to create a snapshot from. Required for creating a snapshot");
    Option snapshotName = new Option("n", "snapshot", true,
            "The snapshot name. Required for importing from S3");
    Option accessId = new Option("k", "awsAccessKey", true, "The AWS access key");
    Option accessSecret = new Option("s", "awsAccessSecret", true, "The AWS access secret string");
    Option bucketName = new Option("b", "bucketName", true, "The S3 bucket name where snapshots are stored");
    Option s3Path = new Option("p", "s3Path", true, "The snapshot directory in S3. Default is '/hbase'");
    Option hdfsPath = new Option("d", "hdfsPath", true, "The snapshot directory in HDFS. Default is '/hbase'");
    Option mappers = new Option("m", "mappers", true,
            "The number of parallel copiers if copying to/from S3. Default: 1");
    Option useS3n = new Option("a", "s3n", false,
            "Use s3n protocol instead of s3. Might work better, but beware of 5GB file limit imposed by S3");
    Option snapshotTtl = new Option("l", "snapshotTtl", true,
            "Delete snapshots older than this value (seconds) from running HBase cluster");

    tableName.setRequired(false);
    snapshotName.setRequired(false);
    accessId.setRequired(true);
    accessSecret.setRequired(true);
    bucketName.setRequired(true);
    s3Path.setRequired(false);
    hdfsPath.setRequired(false);
    mappers.setRequired(false);
    useS3n.setRequired(false);
    snapshotTtl.setRequired(false);

    Option createSnapshot = new Option("c", "create", false, "Create HBase snapshot");
    Option createExportSnapshot = new Option("x", "createExport", false,
            "Create HBase snapshot AND export to S3");
    Option exportSnapshot = new Option("e", "export", false, "Export HBase snapshot to S3");
    Option importSnapshot = new Option("i", "import", false,
            "Import HBase snapshot from S3. May need to run as hbase user if importing into HBase");

    OptionGroup actions = new OptionGroup();
    actions.setRequired(true);
    actions.addOption(createSnapshot);
    actions.addOption(createExportSnapshot);
    actions.addOption(exportSnapshot);
    actions.addOption(importSnapshot);

    Options options = new Options();
    options.addOptionGroup(actions);
    options.addOption(tableName);
    options.addOption(snapshotName);
    options.addOption(accessId);
    options.addOption(accessSecret);
    options.addOption(bucketName);
    options.addOption(s3Path);
    options.addOption(hdfsPath);
    options.addOption(mappers);
    options.addOption(useS3n);
    options.addOption(snapshotTtl);

    return options;
}

From source file:at.newmedialab.ldpath.backend.linkeddata.LDQuery.java

private static Options buildOptions() {
    Options result = new Options();

    OptionGroup query = new OptionGroup();
    Option path = OptionBuilder.withArgName("path").hasArg()
            .withDescription("LD Path to evaluate on the file starting from the context").create("path");
    Option program = OptionBuilder.withArgName("file").hasArg()
            .withDescription("LD Path program to evaluate on the file starting from the context")
            .create("program");
    query.addOption(path);
    query.addOption(program);/*from  w  w  w. j  a v a  2s  .c o m*/
    query.setRequired(true);
    result.addOptionGroup(query);

    Option context = OptionBuilder.withArgName("uri").hasArg()
            .withDescription("URI of the context node to start from").create("context");
    context.setRequired(true);
    result.addOption(context);

    Option loglevel = OptionBuilder.withArgName("level").hasArg()
            .withDescription("set the log level; default is 'warn'").create("loglevel");
    result.addOption(loglevel);

    Option store = OptionBuilder.withArgName("dir").hasArg()
            .withDescription("cache the retrieved data in this directory").create("store");
    result.addOption(store);

    return result;
}

From source file:de.zib.chordsharp.Main.java

/**
 * creates the options the command line should understand
 * //from  w  w w. java 2 s . c  om
 * @return the options the program understands
 */
private static Options getOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup();

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

    Option read = OptionBuilder.create("read");
    read.setArgName("key");
    read.setArgs(1);
    read.setDescription("read an item");
    //      Option read = OptionBuilder.withArgName("key").hasArg()
    //            .withDescription("read an item").create("read");
    group.addOption(read);

    Option write = OptionBuilder.create("write");
    write.setArgName("params");
    write.setArgs(2);
    write.setDescription("write an item: <key> <value>");
    //      Option write = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("write an item: <key> <value>")
    //            .create("write");
    group.addOption(write);

    Option publish = OptionBuilder.create("publish");
    publish.setArgName("params");
    publish.setArgs(2);
    publish.setDescription("publish a new message for a topic: <topic> <message>");
    //      Option publish = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription(
    //                  "publish a new message for a topic: <topic> <message>")
    //            .create("publish");
    group.addOption(publish);

    Option subscribe = OptionBuilder.create("subscribe");
    subscribe.setArgName("params");
    subscribe.setArgs(2);
    subscribe.setDescription("subscribe to a topic: <topic> <url>");
    //      Option subscribe = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("subscribe to a topic: <topic> <url>").create(
    //                  "subscribe");
    group.addOption(subscribe);

    Option unsubscribe = OptionBuilder.create("unsubscribe");
    unsubscribe.setArgName("params");
    unsubscribe.setArgs(2);
    unsubscribe.setDescription("unsubscribe from a topic: <topic> <url>");
    //      Option subscribe = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("unsubscribe from a topic: <topic> <url>").create(
    //                  "unsubscribe");
    group.addOption(unsubscribe);

    Option getSubscribers = OptionBuilder.create("getsubscribers");
    getSubscribers.setArgName("topic");
    getSubscribers.setArgs(1);
    getSubscribers.setDescription("get subscribers of a topic");
    //      Option getSubscribers = OptionBuilder.withArgName("topic").hasArgs(1)
    //            .withDescription("get subscribers of a topic").create(
    //                  "getsubscribers");
    group.addOption(getSubscribers);

    options.addOption(new Option("minibench", "run mini benchmark"));

    options.addOptionGroup(group);

    return options;
}

From source file:de.unibi.techfak.bibiserv.util.codegen.Main.java

/**
 * Returns "Choice" optiongroup for CodeGeneration.
 *
 * @return/*w w  w .j  a v  a 2  s .  c  o  m*/
 */
private static OptionGroup getCMDLineOptionsGroups() {
    OptionGroup optionsgroup = new OptionGroup();
    optionsgroup.setRequired(true);
    Option generate = new Option("g", "generate", true, "Generate app from xml description.");
    generate.setArgName("runnableitem.xml");
    optionsgroup.addOption(new Option("V", "version", false, "version"))
            .addOption(new Option("h", "help", false, "help")).addOption(generate);

    return optionsgroup;
}

From source file:it.uniud.ailab.dcore.launchers.Launcher.java

/**
 * Generates the command-line options.//from  ww w.  j  a  v a  2  s  .co  m
 */
private static void createOptions() {
    // help message
    options.addOption(Option.builder("h").longOpt("help").desc("Display this message").hasArg(false).build());

    // work modes: evaluation
    options.addOption(Option.builder("e").longOpt("evaluate")
            .desc("Evaluate the pipeline using the DATASET dataset").hasArg(true).argName("DATASET").build());

    // work modes: training
    options.addOption(Option.builder("t").longOpt("training-generation")
            .desc("Generate a training set for machine learning " + "using the DATASET dataset").hasArg(true)
            .argName("DATASET").build());

    // load the pipeline
    options.addOption(Option.builder("c").longOpt("config-file").desc("Use the configuration located in PATH")
            .hasArg(true).argName("FILE").build());

    // load the pipeline-2
    options.addOption(Option.builder("cd").longOpt("config-default")
            .desc("Use one of the default configurations (deprecated)").hasArg(true).argName("PIPELINE")
            .build());

    // load the pipeline-3
    options.addOption(Option.builder("cp").longOpt("config-packaged")
            .desc("Use one of the pre-packaged configurations").hasArg(true).argName("PIPELINE").build());

    OptionGroup inputGroup = new OptionGroup();
    //inputGroup.setRequired(true);

    // load the input file
    inputGroup.addOption(Option.builder("f").longOpt("file").desc("Analyze the input file FILE").hasArg(true)
            .argName("FILE").build());

    // load the input directory
    inputGroup.addOption(Option.builder("d").longOpt("dir")
            .desc("Analyze all files contained in DIR (not recursive)").hasArg(true).argName("DIR").build());

    options.addOptionGroup(inputGroup);

    // set the output file prefix
    options.addOption(Option.builder("o").longOpt("output-folder").desc("Write the output in PATH").hasArg(true)
            .argName("PATH").build());

    // verbose distillation
    options.addOption(Option.builder("v").longOpt("verbose").desc("Print details while extracting")
            .hasArg(false).build());

    options.addOption(Option.builder("l").longOpt("language").desc("LANGUAGE of the input document (optional)")
            .hasArg(true).argName("LANGUAGE").build());
}

From source file:net.sourceforge.czt.gnast.Gnast.java

/**
 * Parses the arguments from the command line.
 *
 * @return a configured GnAST builder if parsing was successful;
 *         {@code null} otherwise.// w w w .j a  va  2s.  c o  m
 * @throws NullPointerException if {@code args} is {@code null}
 */
@SuppressWarnings("static-access")
private static GnastBuilder parseArguments(String[] args) {

    Options argOptions = new Options();

    OptionGroup verboseOptions = new OptionGroup();
    verboseOptions.addOption(OptionBuilder.withLongOpt("verbose")
            .withDescription("Verbose; display verbose debugging messages").create("v"));
    verboseOptions.addOption(OptionBuilder.withLongOpt("vverbose")
            .withDescription("Very verbose; more verbose debugging messages").create("vv"));
    verboseOptions.addOption(OptionBuilder.withLongOpt("vvverbose")
            .withDescription("Very very verbose; even more verbose debugging messages").create("vvv"));
    argOptions.addOptionGroup(verboseOptions);

    argOptions.addOption(OptionBuilder.withLongOpt("finalizers")
            .withDescription("Add AST finalisers. WARNING: ASTs will consume more memory!").create("f"));

    argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("destination")
            .withDescription("Generated files go into this directory").create("d"));

    argOptions.addOption(OptionBuilder.withArgName("dir1 dir2").hasArgs().withValueSeparator(',')
            .withLongOpt("templates").withDescription("Additional template directories").create("t"));

    argOptions.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("mapping")
            .withDescription("XML type mapping properties file").create("m"));

    argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("source").withDescription(
            "The directory with all ZML schema files. The requested project namespace must be present, as well as all its parents.")
            .create("s"));

    argOptions.addOption(OptionBuilder.withArgName("url").hasArg().withLongOpt("namespace")
            .withDescription("The namespace of the project to be generated.").create("n"));

    // use GNU parser that allows longer option name (e.g. `-vvv`)
    CommandLineParser parser = new GnuParser();
    CommandLine line;
    try {
        // parse the command line arguments
        line = parser.parse(argOptions, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println(exp.getMessage());

        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("gnast", argOptions, true);

        return null;
    }

    Level verbosity = line.hasOption("v") ? Level.INFO
            : (line.hasOption("vv") ? Level.FINE : (line.hasOption("vvv") ? Level.FINER : Level.OFF));

    String[] templates = line.getOptionValues("t");
    List<URL> templateDirs = new ArrayList<URL>();
    for (String path : templates) {
        templateDirs.add(toURL(path));
    }

    return new GnastBuilder().verbosity(verbosity).finalizers(line.hasOption("f"))
            .destination(toFile(line.getOptionValue("d"))).templates(templateDirs)
            .mapping(toURL(line.getOptionValue("m"))).sourceSchemas(schemaDirToURL(line.getOptionValue("s")))
            .namespace(line.getOptionValue("n"));
}