Example usage for org.apache.commons.cli Option Option

List of usage examples for org.apache.commons.cli Option Option

Introduction

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

Prototype

public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:com.momab.dstool.DSTool.java

static Options commandLineOptions() {

    Option help = new Option("h", "help", false, "print this message");
    Option username = new Option("u", "username", true,
            "Username to use when sending requests to the remote app");
    Option password = new Option("p", "password", true,
            "Password to use when sending requests to the remote app");
    Option port = new Option("P", "port", true,
            "Network port used when connecting to the app, if omitted the default port 80 wil be used");

    Option read = new Option("r", "read", false,
            "download all entites of the specified kind from the" + "remote app datastore");
    Option write = new Option("w", "write", false,
            "upload entites of the specified kind to the remote" + " app datastore");
    Option delete = new Option("d", "delete", false,
            "delete all entities of the specified kind from the remote" + " app datastore");
    Option file = new Option("f", "file", true, "specify a file name to read/write local entity data from/to"
            + ", stdin/stdout will be used of the filename is omitted");

    OptionGroup operations = new OptionGroup();
    operations.addOption(read);//from  ww w .  j  a  v  a2  s.co  m
    operations.addOption(write);
    operations.addOption(delete);

    Options options = new Options();

    options.addOptionGroup(operations);
    options.addOption(file);
    options.addOption(help);
    options.addOption(username);
    options.addOption(password);
    options.addOption(port);

    return options;
}

From source file:cz.muni.fi.crocs.JeeTool.OptionsMain.java

public static Options createOptions() {
    Option help = new Option("h", "help", false, "show help and exit");

    Option motes = new Option("a", "motes", true,
            "path to alternative file of motes, default setting is stored in /opt/motePaths.txt");
    Option ids = new Option("i", "id", true,
            "select IDs of nodes from motelist, use comma separated list of IDs or ID ranges, such as 1,3,5-7,9-15");

    Option detect = new Option("d", "detect", false, "Perform node detection only");

    Option verbose = new Option("v", "verbose", false, "show extended text output");
    Option silent = new Option("s", "silent", false, "show limited text output");
    OptionGroup output = new OptionGroup();
    output.addOption(verbose);//www. j a va  2s . c  o  m
    output.addOption(silent);

    Option make = new Option("m", "make", true, "make target at this path, .ino file required");
    Option makeUpload = new Option("u", "make_upload", true,
            "make target  at this path and upload to nodes, .ino file required");
    Option threads = new Option("t", "threads", false, "use threads for paralell upload");

    OptionGroup makeGroup = new OptionGroup();
    makeGroup.addOption(make);
    makeGroup.addOption(makeUpload);

    Options options = new Options();

    options.addOption(help);
    options.addOption(motes);
    options.addOption(ids);
    options.addOption(detect);

    options.addOptionGroup(output);
    options.addOptionGroup(makeGroup);

    options.addOption(threads);
    return options;
}

From source file:com.alibaba.rocketmq.example.operation.Producer.java

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    // ////////////////////////////////////////////////////
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);//from w  ww. j av  a2 s  .  c  om
    options.addOption(opt);

    opt = new Option("g", "producerGroup", true, "Producer Group Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("a", "tags", true, "Tags Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("k", "keys", true, "Keys Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("c", "msgCount", true, "Message Count");
    opt.setRequired(true);
    options.addOption(opt);

    // ////////////////////////////////////////////////////

    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }

    return commandLine;
}

From source file:cz.muni.fi.crocs.EduHoc.OptionsMain.java

public static Options createOptions() {
    Option help = new Option("h", "help", false, "show help and exit");

    Option motes = new Option("a", "motes", true,
            "path to alternative file of motes, default setting is stored in confix/motePaths.txt");
    Option ids = new Option("i", "id", true,
            "select IDs of nodes from motelist, use comma separated list of IDs or ID ranges, such as 1,3,5-7,9-15");

    Option detect = new Option("d", "detect", false, "Perform node detection only");

    Option verbose = new Option("v", "verbose", false, "show extended text output");
    Option silent = new Option("s", "silent", false, "show limited text output");
    OptionGroup output = new OptionGroup();
    output.addOption(verbose);/*from   w w  w  .  j  a  v a2 s . com*/
    output.addOption(silent);

    Option make = new Option("m", "make", true, "make target at this path, directory must contain Makefile");
    Option makeClean = new Option("c", "make_clean", true,
            "make clean target at this path, directory must contain Makefile");
    Option makeUpload = new Option("u", "make_upload", true,
            "make target  at this path and upload to nodes, directory must contain Makefile");
    Option threads = new Option("t", "threads", false, "use threads for paralell upload");

    OptionGroup makeGroup = new OptionGroup();
    makeGroup.addOption(make);
    makeGroup.addOption(makeUpload);
    makeGroup.addOption(makeClean);

    Option listen = new Option("l", "listen", true,
            "connect to serial and save stream to files, set path to directory for files");
    Option write = new Option("w", "write", true,
            "write to serial now or after upload, directory must contain at least one file with same name as node");

    Option execute = new Option("E", "execute", true, "path to shell script to be executed in phase 3");
    Option time = new Option("T", "time", true,
            "countdown in minutes for serial phase, default is 15 minutes, after this time, serial connection closes");
    time.setType(int.class);

    Options options = new Options();

    options.addOption(help);
    options.addOption(motes);
    options.addOption(ids);
    options.addOption(detect);

    options.addOptionGroup(output);

    options.addOptionGroup(makeGroup);

    options.addOption(threads);
    options.addOption(write);
    options.addOption(listen);

    options.addOption(execute);
    options.addOption(time);

    return options;
}

From source file:com.alibaba.rocketmq.example.operation.Consumer.java

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    // ////////////////////////////////////////////////////
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);/*from  w  ww  .  j ava  2s .c o  m*/
    options.addOption(opt);

    opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("s", "subscription", true, "subscription");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
    opt.setRequired(true);
    options.addOption(opt);

    // ////////////////////////////////////////////////////

    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }

    return commandLine;
}

From source file:Generate.java

private static void optionSetup() {
    options = new Options();

    Option help = new Option("h", "help", false, "print usage of Pyjama compiler");
    help.setRequired(false);// w w w .  j a  v  a 2  s  . c  om
    options.addOption(help);

    Option classpath = new Option("cp", "classpath", true,
            "Specify where to find user class files and annotation processors");
    classpath.setRequired(false);
    classpath.setArgs(1);
    classpath.setArgName("PATH");
    options.addOption(classpath);

    Option outputPath = new Option("d", "directory", true, "output file directory");
    outputPath.setRequired(false);
    outputPath.setArgs(1);
    outputPath.setArgName("DIR");
    options.addOption(outputPath);

    Option j2c = new Option("j2c", "javatoclass", false,
            "(default)compile .java file to paralleled .class file");
    j2c.setRequired(false);
    options.addOption(j2c);

    Option j2j = new Option("j2j", "javatojava", false,
            "compile .java file to paralleled .java file. "
                    + "Remember new parallel java file will overwrite old sequential java file, "
                    + "if there is no target directory is specified.");
    j2j.setRequired(false);
    options.addOption(j2j);

    Option p2c = new Option("p2c", "pjtoclass", false, "compile .pj file to paralleled .class file");
    p2c.setRequired(false);
    options.addOption(p2c);

    Option p2j = new Option("p2j", "pjtojava", false, "compile .pj file to paralleled .java file");
    p2j.setRequired(false);
    options.addOption(p2j);
}

From source file:gov.nasa.jpl.mudrod.main.MudrodEngine.java

/**
 * Main program invocation. Accepts one argument denoting location (on disk)
 * to a log file which is to be ingested. Help will be provided if invoked
 * with incorrect parameters.//from  w w  w. j a va2  s.  c o m
 *
 * @param args
 *          {@link java.lang.String} array contaning correct parameters.
 */
public static void main(String[] args) {
    // boolean options
    Option helpOpt = new Option("h", "help", false, "show this help message");

    // log ingest (preprocessing + processing)
    Option logIngestOpt = new Option("l", LOG_INGEST, false, "begin log ingest");
    // metadata ingest (preprocessing + processing)
    Option metaIngestOpt = new Option("m", META_INGEST, false, "begin metadata ingest");
    // ingest both log and metadata
    Option fullIngestOpt = new Option("f", FULL_INGEST, false, "begin full ingest Mudrod workflow");
    // processing only, assuming that preprocessing results is in dataDir
    Option processingOpt = new Option("p", PROCESSING, false, "begin processing with preprocessing results");

    // argument options
    Option dataDirOpt = OptionBuilder.hasArg(true).withArgName("/path/to/data/directory").hasArgs(1)
            .withDescription("the data directory to be processed by Mudrod").withLongOpt("dataDirectory")
            .isRequired().create(DATA_DIR);

    Option esHostOpt = OptionBuilder.hasArg(true).withArgName("host_name").hasArgs(1)
            .withDescription("elasticsearch cluster unicast host").withLongOpt("elasticSearchHost")
            .isRequired(false).create(ES_HOST);

    Option esTCPPortOpt = OptionBuilder.hasArg(true).withArgName("port_num").hasArgs(1)
            .withDescription("elasticsearch transport TCP port").withLongOpt("elasticSearchTransportTCPPort")
            .isRequired(false).create(ES_TCP_PORT);

    Option esPortOpt = OptionBuilder.hasArg(true).withArgName("port_num").hasArgs(1)
            .withDescription("elasticsearch HTTP/REST port").withLongOpt("elasticSearchHTTPPort")
            .isRequired(false).create(ES_HTTP_PORT);

    // create the options
    Options options = new Options();
    options.addOption(helpOpt);
    options.addOption(logIngestOpt);
    options.addOption(metaIngestOpt);
    options.addOption(fullIngestOpt);
    options.addOption(processingOpt);
    options.addOption(dataDirOpt);
    options.addOption(esHostOpt);
    options.addOption(esTCPPortOpt);
    options.addOption(esPortOpt);

    CommandLineParser parser = new GnuParser();
    try {
        CommandLine line = parser.parse(options, args);
        String processingType = null;

        if (line.hasOption(LOG_INGEST)) {
            processingType = LOG_INGEST;
        } else if (line.hasOption(PROCESSING)) {
            processingType = PROCESSING;
        } else if (line.hasOption(META_INGEST)) {
            processingType = META_INGEST;
        } else if (line.hasOption(FULL_INGEST)) {
            processingType = FULL_INGEST;
        }

        String dataDir = line.getOptionValue(DATA_DIR).replace("\\", "/");
        if (!dataDir.endsWith("/")) {
            dataDir += "/";
        }

        MudrodEngine me = new MudrodEngine();
        me.loadConfig();
        me.props.put(DATA_DIR, dataDir);

        if (line.hasOption(ES_HOST)) {
            String esHost = line.getOptionValue(ES_HOST);
            me.props.put(MudrodConstants.ES_UNICAST_HOSTS, esHost);
        }

        if (line.hasOption(ES_TCP_PORT)) {
            String esTcpPort = line.getOptionValue(ES_TCP_PORT);
            me.props.put(MudrodConstants.ES_TRANSPORT_TCP_PORT, esTcpPort);
        }

        if (line.hasOption(ES_HTTP_PORT)) {
            String esHttpPort = line.getOptionValue(ES_HTTP_PORT);
            me.props.put(MudrodConstants.ES_HTTP_PORT, esHttpPort);
        }

        me.es = new ESDriver(me.getConfig());
        me.spark = new SparkDriver(me.getConfig());
        loadFullConfig(me, dataDir);
        if (processingType != null) {
            switch (processingType) {
            case PROCESSING:
                me.startProcessing();
                break;
            case LOG_INGEST:
                me.startLogIngest();
                break;
            case META_INGEST:
                me.startMetaIngest();
                break;
            case FULL_INGEST:
                me.startFullIngest();
                break;
            default:
                break;
            }
        }
        me.end();
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.",
                options, true);
        LOG.error("Error whilst parsing command line.", e);
    }
}

From source file:com.twcable.grabbit.tools.cli.CliOptions.java

/**
 * Parse the arguments./*from w ww.jav a2s.  co m*/
 *
 * @param args the command line arguments
 * @return Right if successfully parsed; otherwise Left with the error message/help
 */
@SuppressWarnings("PMD.UseVarargs")
public static Either<String, CliOptions> create(String[] args) {
    val help = new Option("h", "help", false, "Show usage information");
    val start = new Option("s", "start", false, "Start Grabbit");
    val monitor = new Option("m", "monitor", false, "Monitor Grabbit");

    val options = new Options();
    options.addOption(help);
    options.addOption(start);
    options.addOption(monitor);

    val parser = new DefaultParser();
    try {
        // parse the command line arguments
        val line = parser.parse(options, args);

        if (line.hasOption('h') || !hasValidOptions(line)) {
            val formatter = new HelpFormatter();
            val stringWriter = new StringWriter();
            formatter.printHelp(new PrintWriter(stringWriter), formatter.getWidth(),
                    "grabbit-cli -[h|s|sm|m] [grabbit-job-config-file] [env-config-file] [env] [job-ids-cache-file]",
                    "Starts and/or monitors jobs on the Grabbit client", options, formatter.getLeftPadding(),
                    formatter.getDescPadding(), "", false);
            return Either.left(stringWriter.toString());
        }

        val argList = line.getArgList();

        if (line.hasOption('s')) {
            return Either.right(new CliOptions(true, line.hasOption('m'), argList.get(0), argList.get(1),
                    argList.get(2), null));
        } else {
            return Either
                    .right(new CliOptions(false, true, null, argList.get(0), argList.get(1), argList.get(2)));
        }
    } catch (ParseException exp) {
        return Either.left("Parsing failed.  Reason: " + exp.getMessage());
    }
}

From source file:com.alibaba.rocketmq.filtersrv.FiltersrvStartup.java

public static Options buildCommandlineOptions(final Options options) {
    Option opt = new Option("c", "configFile", true, "Filter server config properties file");
    opt.setRequired(false);// w w  w  . j  a v  a  2s  . c  om
    options.addOption(opt);

    opt = new Option("p", "printConfigItem", false, "Print all config item");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}

From source file:info.bitoo.Daemon.java

private static Options createCommandLineOptions() {
    Option optConfig = new Option("c", "config", true, "configuration file location");

    Option optPipe = new Option("p", "pipe", true, "unix pipe path");
    optPipe.setRequired(true);//from w  w  w. j a v  a2s  .co  m

    Options cliOptions = new Options();
    cliOptions.addOption(optConfig);
    cliOptions.addOption(optPipe);

    return cliOptions;
}