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

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

Introduction

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

Prototype

public static OptionBuilder hasArg() 

Source Link

Document

The next Option created will require an argument value.

Usage

From source file:com.google.code.linkedinapi.client.examples.PostNetworkUpdateExample.java

/**
  * Build command line options object./*w  ww.  ja  v  a  2 s  .c om*/
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String updateMsg = "Text of the update.";
    OptionBuilder.withArgName("update");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(updateMsg);
    Option update = OptionBuilder.create(UPDATE_TEXT_OPTION);
    opts.addOption(update);

    return opts;
}

From source file:chibi.gemmaanalysis.OutlierDetectionTestCli.java

@Override
@SuppressWarnings("static-access")
protected void buildOptions() {
    super.buildOptions();
    Option outputFileOption = OptionBuilder.hasArg().withArgName("filename")
            .withDescription("Name and path of output file.").withLongOpt("output").create('o');

    addOption(outputFileOption);// ww  w  . j  av  a 2  s . c  om

    Option regressionOption = OptionBuilder.withArgName("regression")
            .withDescription("Regress out significant experimental factors before detecting outliers.")
            .withLongOpt("regression").create('r');

    addOption(regressionOption);

    Option findByMedianOption = OptionBuilder.withArgName("findByMedian")
            .withDescription(
                    "Find outliers by comparing first, second, or third quartiles of sample correlations.")
            .withLongOpt("findByMedian").create('m');

    addOption(findByMedianOption);

    Option combinedMethodOption = OptionBuilder.withArgName("combinedMethod")
            .withDescription("Combine results from two outlier detection methods.").withLongOpt("combined")
            .create('c');

    addOption(combinedMethodOption);
}

From source file:com.mellanox.r4h.MiniDFSClusterManager.java

/**
 * Creates configuration options object.
 *//*from  w w  w  . j av  a  2s .c  om*/
@SuppressWarnings("static-access")
private Options makeOptions() {
    Options options = new Options();
    options.addOption("datanodes", true, "How many datanodes to start (default 1)")
            .addOption("format", false, "Format the DFS (default false)")
            .addOption("cmdport", true, "Which port to listen on for commands (default 0--we choose)")
            .addOption("nnport", true, "NameNode port (default 0--we choose)")
            .addOption("namenode", true,
                    "URL of the namenode (default " + "is either the DFS cluster or a temporary dir)")
            .addOption(OptionBuilder.hasArgs().withArgName("property=value")
                    .withDescription("Options to pass into configuration object").create("D"))
            .addOption(OptionBuilder.hasArg().withArgName("path")
                    .withDescription("Save configuration to this XML file.").create("writeConfig"))
            .addOption(OptionBuilder.hasArg().withArgName("path")
                    .withDescription("Write basic information to this JSON file.").create("writeDetails"))
            .addOption(OptionBuilder.withDescription("Prints option help.").create("help"));
    return options;
}

From source file:com.google.code.linkedinapi.client.examples.MessagingApiExample.java

/**
  * Build command line options object./*from w  ww.j a va  2  s .  c  om*/
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String idMsg = "IDs of the users to whom a message is to be sent (separated by comma).";
    OptionBuilder.withArgName("ids");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String subjectMsg = "Subject of the message.";
    OptionBuilder.withArgName("subject");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(subjectMsg);
    Option subject = OptionBuilder.create(SUBJECT_OPTION);
    opts.addOption(subject);

    String messageMsg = "Content of the message.";
    OptionBuilder.withArgName("message");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(messageMsg);
    Option message = OptionBuilder.create(MESSAGE_OPTION);
    opts.addOption(message);

    return opts;
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static boolean loadConfiguration(String[] args, String configFile) throws Exception {
    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("config file");
    OptionBuilder.withLongOpt("config");
    Option configFileOption = OptionBuilder.create("C");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);//from w  w  w. jav a2s .c o  m
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("properties that overrides the ones in config file");
    OptionBuilder.withLongOpt("properties");
    Option propertiesOption = OptionBuilder.create("P");

    Options options = new Options();
    options.addOption(configFileOption);
    options.addOption(propertiesOption);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.out.println(pe.getMessage());
        return false;
    }

    InputStream in = null;

    if (configFile == null || configFile.trim().isEmpty()) {
        configFile = cmd.getOptionValue("C");
        if (configFile != null && new File(configFile).isFile()) {
            in = new FileInputStream(configFile);
        }
    } else {
        in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile);
    }
    if (in != null) {
        try {
            ConfigManager.getInstance().loadProperties(in);
        } catch (IOException ioe) {
            System.out.println("invalid config file: " + configFile);
            return false;
        } finally {
            in.close();
        }
    }

    Properties properties = cmd.getOptionProperties("P");
    if (properties != null) {
        ConfigManager.getInstance().putAll(properties);
    }

    return !ConfigManager.getInstance().getProperties().isEmpty();
}

From source file:jurbano.melodyshape.ui.ConsoleUIObserver.java

/**
 * Constructs a new {@code ConsoleUIObserver} according to some command line
 * arguments.//w w  w  .ja v a 2  s.co  m
 * 
 * @param args
 *            the command line arguments to configure the algorithm.
 */
@SuppressWarnings("static-access")
public ConsoleUIObserver(String[] args) {
    this.args = args;

    this.qOpt = null;
    this.cOpt = null;
    this.aOpt = null;
    this.lOpt = false;
    this.hOpt = false;
    this.tOpt = Runtime.getRuntime().availableProcessors();
    this.kOpt = Integer.MAX_VALUE;
    this.vOpt = 0;

    this.options = new Options();
    // required arguments
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("file/dir")
            .withDescription("path to the query melody or melodies.").create("q"));
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("dir")
            .withDescription("path to the collection of documents.").create("c"));
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("name")
            .withDescription("algorithm to run:" + "\n- 2010-domain, 2010-pitchderiv, 2010-shape"
                    + "\n- 2011-shape, 2011-pitch, 2011-time"
                    + "\n- 2012-shapeh, 2012-shapel, 2012-shapeg, 2012-time, 2012-shapetime"
                    + "\n- 2013-shapeh, 2013-time, 2013-shapetime"
                    + "\n- 2014-shapeh, 2014-time, 2014-shapetime"
                    + "\n- 2015-shapeh, 2015-time, 2015-shapetime")
            .create("a"));
    // optional arguments
    this.options.addOption(OptionBuilder
            .withDescription("show results in a single line (omits similarity scores).").create("l"));
    this.options.addOption(OptionBuilder.hasArg().withArgName("num")
            .withDescription("run a fixed number of threads.").create("t"));
    this.options.addOption(OptionBuilder.hasArg().withArgName("cutoff")
            .withDescription("number of documents to retrieve.").create("k"));
    this.options.addOption(OptionBuilder.withDescription("verbose, to stderr.").create("v"));
    this.options.addOption(OptionBuilder.withDescription("verbose a lot, to stderr.").create("vv"));
    this.options.addOption(OptionBuilder.withDescription("show this help message.").create("h"));
    this.options.addOption(OptionBuilder.withDescription("run with graphical user interface.").create("gui"));
}

From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java

private static void parseCommandLine(String[] args) {
    CommandLine cmd = null;/*ww w  .j  a  v a  2 s .co m*/
    Options parserOptions = new Options();
    parserOptions.addOption(OPTION_DEBUG, false, "marks this session as a debug session");
    OptionBuilder.withArgName(OPTION_DIR);
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the directory with the config files");
    parserOptions.addOption(OptionBuilder.create(OPTION_DIR));

    try {
        cmd = parser.parse(parserOptions, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        System.out.println("EzDL " + EzDLConstants.CLIENT_VERSION);
        formatter.printHelp("ezdl", parserOptions);
        System.exit(1);
    }

    if (cmd.hasOption(OPTION_DEBUG)) {
        System.out.println("debug option found");
        sessionType = SessionType.DEBUG;
    } else {
        sessionType = DEFAULT_SESSION_TYPE;
    }

    if (cmd.hasOption(OPTION_DIR)) {
        String dir = cmd.getOptionValue(OPTION_DIR);
        Config.setPropertyDir(dir);
        PropertiesUtils.setPropertyDir(dir);
        Config.getInstance().refreshProperties();
    }
}

From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java

/**
 * Creates and adds a minimum state size option to a given {@link Options}
 * object./* w  w  w  . j a  va  2 s.c  o m*/
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addMinStateSizeOption(final Options options) {
    OptionBuilder.withLongOpt(MIN_STATE_SIZE_KEY_LONG);
    OptionBuilder.withDescription(MIN_STATE_SIZE_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(SIZE_ARG_NAME);
    OptionBuilder.withType(int.class);

    final Option minStateSize = OptionBuilder.create(MIN_STATE_SIZE_KEY);
    options.addOption(minStateSize);
}

From source file:com.google.code.linkedinapi.client.examples.OAuthAuthenticationExample.java

/**
  * Build command line options object.//  w w w.  j  a  v  a 2  s.  co  m
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    return opts;
}

From source file:com.google.code.linkedinapi.client.examples.ProfileApiExample.java

/**
  * Build command line options object./*  w w  w .j av a 2  s.  c  o  m*/
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String idMsg = "ID of the user whose profile is to be fetched.";
    OptionBuilder.withArgName("id");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String urlMsg = "Profile URL of the user whose profile is to be fetched.";
    OptionBuilder.withArgName("url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(urlMsg);
    Option url = OptionBuilder.create(URL_OPTION);
    opts.addOption(url);

    String typeMsg = "Type of profile. Either standard or public.";
    OptionBuilder.withArgName("type");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(typeMsg);
    Option type = OptionBuilder.create(TYPE_OPTION);
    opts.addOption(type);

    return opts;
}