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:chibi.gemmaanalysis.AffyPlatFormAnalysisCli.java

@SuppressWarnings("static-access")
@Override//from   w  w  w .j  av  a 2 s . co m
protected void buildOptions() {
    Option ADOption = OptionBuilder.hasArg().isRequired().withArgName("arrayDesign")
            .withDescription("Array Design Short Name (GPLXXX) ").withLongOpt("arrayDesign").create('a');
    addOption(ADOption);
    Option OutOption = OptionBuilder.hasArg().isRequired().withArgName("outputFile")
            .withDescription("The name of the file to save the output ").withLongOpt("outputFile").create('o');
    addOption(OutOption);
}

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

/**
  * Build command line options object.//from  w  w  w  .j  a v  a2  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);

    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);

    return opts;
}

From source file:chibi.gemmaanalysis.cli.deprecated.ProbeMapperCli.java

@SuppressWarnings("static-access")
@Override// w w  w. j av a 2 s . com
protected void buildOptions() {
    Option blatResultOption = OptionBuilder.hasArg().withArgName("PSL file")
            .withDescription("Blat result file in PSL format").withLongOpt("blatfile").create('b');

    addOption(blatResultOption);

    Option databaseNameOption = OptionBuilder.hasArg().withArgName("database")
            .withDescription("GoldenPath database id (default=" + DEFAULT_DATABASE + ")")
            .withLongOpt("database").create('d');

    addOption(OptionBuilder.hasArg().withArgName("value")
            .withDescription(
                    "Sequence identity threshold, default = " + ProbeMapperConfig.DEFAULT_IDENTITY_THRESHOLD)
            .withLongOpt("identityThreshold").create('i'));

    addOption(OptionBuilder.hasArg().withArgName("value")
            .withDescription("Blat score threshold, default = " + ProbeMapperConfig.DEFAULT_SCORE_THRESHOLD)
            .withLongOpt("scoreThreshold").create('s'));

    addOption(OptionBuilder.hasArg().withArgName("file name")
            .withDescription("File containing Genbank identifiers").withLongOpt("gbfile").create('g'));

    addOption(OptionBuilder.hasArg().withArgName("file name")
            .withDescription("File containing sequences in FASTA format").withLongOpt("fastaFile").create('f'));

    addOption(OptionBuilder.hasArg().withArgName("file name")
            .withDescription("File containing BioSequence primary keys (results are saved to database)")
            .create("seqIds"));

    addOption(OptionBuilder.hasArg().withArgName("file name").withDescription("Output file basename")
            .withLongOpt("outputFile").create('o'));

    addOption(databaseNameOption);

}

From source file:com.google.code.uclassify.client.examples.ClassifyExample.java

/**
 * Build command line options object./*from   w w  w.  j  av a 2s . com*/
 * 
 * @return the options
 */
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 Read Key.";
    OptionBuilder.withArgName("readKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(READ_KEY);
    opts.addOption(consumerKey);

    String idMsg = "Classifier Name";
    OptionBuilder.withArgName("classifier");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(CLASSIFIER);
    opts.addOption(id);

    String urlMsg = "Text to be classified.";
    OptionBuilder.withArgName("text");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(urlMsg);
    Option url = OptionBuilder.create(TEXT);
    opts.addOption(url);

    String typeMsg = "User who owns the classifier.";
    OptionBuilder.withArgName("user");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(typeMsg);
    Option type = OptionBuilder.create(USER);
    opts.addOption(type);

    return opts;
}

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

/**
 * Creates and adds a non-word infile option to a given {@link Options}
 * object./*from   ww w . j a v a 2 s  . c  om*/
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addNonwordInfileOption(final Options options) {
    OptionBuilder.withLongOpt(NONWORD_INFILE_KEY_LONG);
    OptionBuilder.withDescription(NONWORD_INFILE_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(INFILE_ARG_NAME);
    OptionBuilder.withType(File.class);
    final Option nonwordInfile = OptionBuilder.create(NONWORD_INFILE_KEY);
    options.addOption(nonwordInfile);
}

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

/**
  * Build command line options object.//from   w w  w. j a  va 2s .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 subjectMsg = "Subject of the invitation.";
    OptionBuilder.withArgName("subject");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(subjectMsg);
    Option subject = OptionBuilder.create(SUBJECT_OPTION);
    opts.addOption(subject);

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

    String idMsg = "ID of the user to whom invitation has to be sent.";
    OptionBuilder.withArgName("id");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String emailMsg = "Email of the user to whom invitation has to be sent.";
    OptionBuilder.withArgName("email");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(emailMsg);
    Option email = OptionBuilder.create(EMAIL_OPTION);
    opts.addOption(email);

    String firstNameMsg = "First name of the user to whom invitation has to be sent.";
    OptionBuilder.withArgName("firstName");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(firstNameMsg);
    Option firstName = OptionBuilder.create(FIRST_NAME_OPTION);
    opts.addOption(firstName);

    String lastNameMsg = "Last name of the user to whom invitation has to be sent.";
    OptionBuilder.withArgName("lastName");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(lastNameMsg);
    Option lastName = OptionBuilder.create(LAST_NAME_OPTION);
    opts.addOption(lastName);

    String authHeaderMsg = "Auth Header of the user to whom invitation has to be sent.";
    OptionBuilder.withArgName("authHeader");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(authHeaderMsg);
    Option authHeader = OptionBuilder.create(AUTH_HEADER_OPTION);
    opts.addOption(authHeader);

    return opts;
}

From source file:groovy.ui.GroovyMain.java

/**
 * Build the options parser.  Has to be synchronized because of the way Options are constructed.
 *
 * @return an options parser./*  w  ww.j a  va 2 s.  co m*/
 */
@SuppressWarnings("static-access")
private static synchronized Options buildOptions() {
    Options options = new Options();
    options.addOption(OptionBuilder.hasArg().withArgName("path")
            .withDescription("Specify where to find the class files - must be first argument")
            .create("classpath"));
    options.addOption(OptionBuilder.withLongOpt("classpath").hasArg().withArgName("path")
            .withDescription("Aliases for '-classpath'").create("cp"));

    options.addOption(OptionBuilder.withLongOpt("define").withDescription("define a system property")
            .hasArg(true).withArgName("name=value").create('D'));
    options.addOption(OptionBuilder.withLongOpt("disableopt")
            .withDescription("disables one or all optimization elements. "
                    + "optlist can be a comma separated list with the elements: "
                    + "all (disables all optimizations), " + "int (disable any int based optimizations)")
            .hasArg(true).withArgName("optlist").create());
    options.addOption(
            OptionBuilder.hasArg(false).withDescription("usage information").withLongOpt("help").create('h'));
    options.addOption(OptionBuilder.hasArg(false).withDescription("debug mode will print out full stack traces")
            .withLongOpt("debug").create('d'));
    options.addOption(OptionBuilder.hasArg(false).withDescription("display the Groovy and JVM versions")
            .withLongOpt("version").create('v'));
    options.addOption(OptionBuilder.withArgName("charset").hasArg()
            .withDescription("specify the encoding of the files").withLongOpt("encoding").create('c'));
    options.addOption(OptionBuilder.withArgName("script").hasArg()
            .withDescription("specify a command line script").create('e'));
    options.addOption(OptionBuilder.withArgName("extension").hasOptionalArg()
            .withDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')")
            .create('i'));
    options.addOption(OptionBuilder.hasArg(false)
            .withDescription("process files line by line using implicit 'line' variable").create('n'));
    options.addOption(OptionBuilder.hasArg(false)
            .withDescription("process files line by line and print result (see also -n)").create('p'));
    options.addOption(OptionBuilder.withArgName("port").hasOptionalArg()
            .withDescription("listen on a port and process inbound lines (default: 1960)").create('l'));
    options.addOption(OptionBuilder.withArgName("splitPattern").hasOptionalArg()
            .withDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable")
            .withLongOpt("autosplit").create('a'));
    options.addOption(OptionBuilder.withLongOpt("indy")
            .withDescription("enables compilation using invokedynamic").create());
    options.addOption(OptionBuilder.withLongOpt("configscript").hasArg()
            .withDescription("A script for tweaking the configuration options").create());
    options.addOption(OptionBuilder.withLongOpt("basescript").hasArg().withArgName("class")
            .withDescription("Base class name for scripts (must derive from Script)").create('b'));
    return options;

}

From source file:chibi.gemmaanalysis.GeneExpressionWriterCLI.java

@SuppressWarnings("static-access")
@Override/*w  w w  .j a va 2 s  .  c om*/
protected void buildOptions() {
    super.buildOptions();

    addForceOption(null);

    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Query file containing list of gene official symbols");
    OptionBuilder.withArgName("File name");
    OptionBuilder.withLongOpt("queryGeneFile");
    Option queryGeneFileOption = OptionBuilder.create();
    addOption(queryGeneFileOption);
    OptionBuilder.hasArgs();
    OptionBuilder.withArgName("Gene symbol(s)");
    OptionBuilder.withDescription("The query gene symbol(s), comma separated");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withLongOpt("queryGene");
    Option queryGeneOption = OptionBuilder.create();
    addOption(queryGeneOption);

    addOption(OptionBuilder.hasArg().withArgName("outfile").withDescription("Output filename prefix")
            .withLongOpt("outfile").isRequired().create('o'));

}

From source file:chibi.gemmaanalysis.ExperimentMetaDataExtractorCli.java

@Override
@SuppressWarnings("static-access")
protected void buildOptions() {
    super.buildOptions();

    Option expOption = OptionBuilder.hasArg().withArgName("outfile").withDescription("GZipped output filename")
            .withLongOpt("outfile").create('o');

    addOption(expOption);/*from   w  ww  . ja  v a 2  s .c om*/

    // to keep troubled experiments
    this.addForceOption();
}

From source file:cmd.ArgumentHandler.java

/**
 * Parses the options in the command line arguments and returns an array of
 * strings corresponding to the filenames given as arguments only
 *
 * @param args/*from  w w w.  ja  v  a  2s. c o m*/
 * @throws org.apache.commons.cli.ParseException
 */
@SuppressWarnings("static-access")
public void parseCommandLineOptions(String[] args) throws ParseException {

    options = new Options();

    options.addOption("h", "help", false, "Help page for command usage");

    options.addOption("s", false, "SubStructure detection");

    options.addOption("a", false, "Add Hydrogen");

    options.addOption("x", false, "Match Atom Type");

    options.addOption("r", false, "Remove Hydrogen");

    options.addOption("z", false, "Ring matching");

    options.addOption("b", false, "Match Bond types (Single, Double etc)");

    options.addOption(
            OptionBuilder.hasArg().withDescription("Query filename").withArgName("filepath").create("q"));

    options.addOption(
            OptionBuilder.hasArg().withDescription("Target filename").withArgName("filepath").create("t"));

    options.addOption(OptionBuilder.hasArg().withDescription("Add suffix to the files").withArgName("suffix")
            .create("S"));

    options.addOption("g", false, "create png of the mapping");

    options.addOption(OptionBuilder.hasArg().withDescription("Dimension of the image in pixels")
            .withArgName("WIDTHxHEIGHT").create("d"));

    options.addOption("m", false, "Report all Mappings");

    String filterDescr = "Default: 0, Stereo: 1, " + "Stereo+Fragment: 2, Stereo+Fragment+Energy: 3";
    options.addOption(OptionBuilder.hasArg().withDescription(filterDescr).withArgName("number").create("f"));

    options.addOption("A", false, "Appends output to existing files, else creates new files");

    options.addOption(OptionBuilder.withDescription("Do N-way MCS on the target SD file").create("N"));

    options.addOption(OptionBuilder.hasArg().withDescription("Query type (MOL, SMI, etc)").withArgName("type")
            .create("Q"));

    options.addOption(OptionBuilder.hasArg().withDescription("Target type (MOL, SMI, SMIF, etc)")
            .withArgName("type").create("T"));

    options.addOption(OptionBuilder.hasArg().withDescription("Output the substructure to a file")
            .withArgName("filename").create("o"));

    options.addOption(
            OptionBuilder.hasArg().withDescription("Output type (SMI, MOL)").withArgName("type").create("O"));

    options.addOption(OptionBuilder.hasOptionalArgs(2).withValueSeparator().withDescription("Image options")
            .withArgName("option=value").create("I"));

    PosixParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args, true);

    if (line.hasOption('Q')) {
        queryType = line.getOptionValue("Q");
    } //else {
    //            queryType = "MOL";
    //        } //XXX default type?

    if (line.hasOption('T')) {
        targetType = line.getOptionValue("T");
    } else {
        targetType = "MOL";
    }

    if (line.hasOption('a')) {
        this.setApplyHAdding(true);
    }

    if (line.hasOption('r')) {
        this.setApplyHRemoval(true);
    }

    if (line.hasOption('m')) {
        this.setAllMapping(true);
    }

    if (line.hasOption('s')) {
        this.setSubstructureMode(true);
    }

    if (line.hasOption('g')) {
        this.setImage(true);
    }

    if (line.hasOption('b')) {
        this.setMatchBondType(true);
    }

    if (line.hasOption('z')) {
        this.setMatchRingType(true);
    }

    if (line.hasOption('x')) {
        this.setMatchAtomType(true);
    }

    remainingArgs = line.getArgs();

    if (line.hasOption('h') || line.getOptions().length == 0) {
        //            System.out.println("Hello");
        helpRequested = true;
    }

    if (line.hasOption('S')) {
        String[] suffix_reader = line.getOptionValues('S');
        if (suffix_reader.length < 1) {
            System.out.println("Suffix required!");
            helpRequested = true;
        }
        setSuffix(suffix_reader[0]);
        setApplySuffix(true);
    }

    if (line.hasOption('f')) {
        String[] filters = line.getOptionValues('f');
        if (filters.length < 1) {
            System.out.println("Chemical filter required (Ranges: 0 to 3)!");
            helpRequested = true;
        }
        setChemFilter((int) new Integer(filters[0]));
    }

    if (line.hasOption('q')) {
        queryFilepath = line.getOptionValue('q');
    }

    if (line.hasOption('t')) {
        targetFilepath = line.getOptionValue('t');
    }

    if (line.hasOption("A")) {
        this.setAppendMode(true);
    }

    if (line.hasOption("N")) {
        setNMCS(true);
    }

    if (line.hasOption("o")) {
        outputSubgraph = true;
        outputFilepath = line.getOptionValue("o");
    }

    if (line.hasOption("O")) {
        outputFiletype = line.getOptionValue("O");
    } else {
        outputFiletype = "MOL";
    }

    if (line.hasOption("d")) {
        String dimensionString = line.getOptionValue("d");
        if (dimensionString.contains("x")) {
            String[] parts = dimensionString.split("x");
            try {
                setImageWidth(Integer.parseInt(parts[0]));
                setImageHeight(Integer.parseInt(parts[1]));
                System.out.println("set image dim to " + getImageWidth() + "x" + getImageHeight());
            } catch (NumberFormatException nfe) {
                throw new ParseException("Malformed dimension string " + dimensionString);
            }
        } else {
            throw new ParseException("Malformed dimension string " + dimensionString);
        }
    }

    if (line.hasOption("I")) {
        imageProperties = line.getOptionProperties("I");
        if (imageProperties.isEmpty()) {
            // used just "-I" by itself
            isImageOptionHelp = true;
        }
    }
}