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

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

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:eu.skqs.bertie.standalone.BertieStandalone.java

public static void main(String[] args) {

    // Options/*from   w  w  w .  ja  v  a 2s  .  c o m*/
    Option file = OptionBuilder.withArgName("file").withLongOpt("file").hasArg()
            .withDescription("File to annotate").create("f");

    Option directory = OptionBuilder.withArgName("directory").withLongOpt("directory").hasArg()
            .withDescription("Directory to annotate").create("d");

    Option owl = OptionBuilder.withArgName("owl").withLongOpt("owl").hasArg()
            .withDescription("OWL file to use in annotation").create("o");

    Option plain = OptionBuilder.withLongOpt("plain").withDescription("Plain text file format").create("p");

    Option tei = OptionBuilder.withLongOpt("tei").withDescription("TEI file format").create("t");

    Option mode = OptionBuilder.withArgName("extract|minimal|maximal|prosody").withLongOpt("mode").hasArg()
            .withDescription("Mode to operate in").create("m");

    Option clean = OptionBuilder.withArgName("T0,T1,T3").withLongOpt("clean").hasArg()
            .withDescription("Remove gives types, MUST START UPPERCASE").create("c");

    Options options = new Options();
    options.addOption(file);
    options.addOption(directory);
    options.addOption(owl);
    options.addOption(plain);
    options.addOption(tei);
    options.addOption(mode);
    options.addOption(clean);

    CommandLineParser parser = new GnuParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmdline = null;

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    BertieStandalone standalone = new BertieStandalone();
    String documentPath = null;

    // Check for custom OWL
    if (cmdline.hasOption("owl")) {
        owlPath = cmdline.getOptionValue("owl");
    }

    // Check for clean
    if (cmdline.hasOption("clean")) {
        typesToRemove = cmdline.getOptionValue("clean");
    }

    // Check for mode
    if (cmdline.hasOption("mode")) {
        String currentMode = cmdline.getOptionValue("mode");

        if (currentMode.equals("extract")) {
            extractMode = true;
        } else if (currentMode.equals("poetry")) {
            poetryMode = true;
        }

        analysisMode = currentMode;
    }

    // Check for directory option
    if (cmdline.hasOption("directory")) {
        // We support TEI directorys only
        if (!cmdline.hasOption("tei")) {
            logger.log(Level.WARNING, "TEI file format must be selected with directory argument");
            System.exit(-1);
        }

        String directoryPath = cmdline.getOptionValue("directory");

        if (extractMode) {
            try {
                standalone.extractWithCollectionReader(directoryPath);
            } catch (Exception e) {
            }

            System.exit(0);
        }

        try {
            standalone.processWithCollectionReader(directoryPath);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }

        System.exit(0);
    }

    // Check for file option
    if (cmdline.hasOption("file")) {
        // TODO: clean this up
        documentPath = cmdline.getOptionValue("file");
        filePath = cmdline.getOptionValue("file");

        // TEI
        if (cmdline.hasOption("tei")) {
            try {
                processWithFile();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(-1);
            }
            System.exit(0);
        }

        // Check for plain option
        if (!cmdline.hasOption("plain")) {
            logger.log(Level.WARNING, "Plain text format must be selected with file argument");
            System.exit(-1);
        }
    } else {
        logger.log(Level.WARNING, "No file argument given. Quitting.");
        formatter.printHelp("bertie", options);
        System.exit(-1);
    }

    // Make sure we have a document path
    if (documentPath == null) {
        logger.log(Level.WARNING, "Document path is empty. Quitting.");
        System.exit(-1);
    }

    // Read the document
    try {
        String encodingType = "UTF-8";

        BufferedReader fileReader = new BufferedReader(
                new InputStreamReader(new FileInputStream(documentPath), encodingType));

        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = fileReader.readLine()) != null) {
            sb.append(line + newLine);
        }

        String input = sb.toString();
        fileReader.close();

        String output = standalone.process(input);
        if (output == null) {
            logger.log(Level.WARNING, "Empty processing result.");
            System.exit(-1);
        }

        PrintWriter fileWriter = new PrintWriter(documentPath, encodingType);
        fileWriter.write(output);
        fileWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zaradai.kunzite.trader.tools.EodConverterOptionsParser.java

@Override
protected void addOptions(Options options) {
    Option property = OptionBuilder.withLongOpt(PROPERTY_OPTION).withArgName("key=value").hasArgs(2)
            .withValueSeparator().withDescription("Generic key value pair properties").create('p');
    options.addOption(property);//from  ww  w. ja  v  a 2  s  .co m
    options.addOption("s", SOURCE_OPTION, true, "Source folder containing encoded files for input types that "
            + "store their data in folders such as CSV.  If specified the folder must exist");
    Option sourceType = new Option("i", SOURCE_TYPE_OPTION, true,
            "Source input type, e.g. CSV, COMPACT, MONGO");
    sourceType.setRequired(true);
    options.addOption(sourceType);
    options.addOption("t", TARGET_OPTION, true, "Target folder containing encoded files for output types that "
            + "store their data in folders such as CSV.  If specified the folder must exist");
    Option targetType = new Option("o", TARGET_TYPE_OPTION, true,
            "Target output type, e.g. CSV, COMPACT, MONGO");
    targetType.setRequired(true);
    options.addOption(targetType);
    Option symbolsOption = OptionBuilder.withLongOpt(SYMBOLS_OPTION).isRequired().withArgName("values")
            .withValueSeparator(' ').hasArgs(Option.UNLIMITED_VALUES)
            .withDescription("A list of space separated symbols to download data for, e.g. INTC AAPL F AMAT")
            .create("sm");
    options.addOption(symbolsOption);
    options.addOption("th", THREADS_OPTION, true, "Specify number of conversion threads, default is 1");
}

From source file:com.linkedin.databus2.client.util.CheckpointSerializerMain.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_NAME).withDescription(HELP_OPT_DESCR)
            .create(HELP_OPT_CHAR);/*from   www . j  av a 2 s  .  c  om*/
    Option clientPropsOption = OptionBuilder.withLongOpt(CLIENT_PROPS_FILE_OPT_NAME)
            .withDescription(CLIENT_PROPS_FILE_OPT_DESCR).hasArg().withArgName("properties_file")
            .create(CLIENT_PROPS_FILE_OPT_CHAR);
    Option cp3PropsOption = OptionBuilder.withLongOpt(CP3_PROPS_FILE_OPT_NAME)
            .withDescription(CP3_PROPS_FILE_OPT_DESCR).hasArg().withArgName("properties_file")
            .create(CP3_PROPS_FILE_OPT_CHAR);
    Option propsPrefixOption = OptionBuilder.withLongOpt(PROPS_PREFIX_OPT_NAME)
            .withDescription(PROPS_PREFIX_OPT_DESCR).hasArg().withArgName("prefix_string")
            .create(PROPS_PREFIX_OPT_CHAR);
    Option sourcesOption = OptionBuilder.withLongOpt(SOURCES_OPT_NAME).withDescription(SOURCES_OPT_DESCR)
            .hasArg().withArgName("sources_list").create(SOURCES_OPT_CHAR);
    Option scnOptOption = OptionBuilder.withLongOpt(SCN_OPT_NAME).withDescription(SCN_OPT_DESCR).hasArg()
            .withArgName("sequence_number").create(SCN_OPT_CHAR);
    Option actionOption = OptionBuilder.withLongOpt(ACTION_OPT_NAME).withDescription(ACTION_OPT_DESCR).hasArg()
            .withArgName("action").create(ACTION_OPT_CHAR);
    Option sinceScnOptOption = OptionBuilder.withLongOpt(SINCE_SCN_OPT_NAME)
            .withDescription(SINCE_SCN_OPT_DESCR).hasArg().withArgName("sequence_number")
            .create(SINCE_SCN_OPT_CHAR);
    Option startScnOptOption = OptionBuilder.withLongOpt(START_SCN_OPT_NAME)
            .withDescription(START_SCN_OPT_DESCR).hasArg().withArgName("sequence_number")
            .create(START_SCN_OPT_CHAR);
    Option targetScnOptOption = OptionBuilder.withLongOpt(TARGET_SCN_OPT_NAME)
            .withDescription(TARGET_SCN_OPT_DESCR).hasArg().withArgName("sequence_number")
            .create(TARGET_SCN_OPT_CHAR);
    Option typeOption = OptionBuilder.withLongOpt(TYPE_OPT_NAME).withDescription(TYPE_OPT_DESCR).hasArg()
            .withArgName("checkpoint_type").create(TYPE_OPT_CHAR);
    Option bootstrapSourceOption = OptionBuilder.withLongOpt(BOOTSTRAP_SOURCE_OPT_NAME)
            .withDescription(BOOTSTRAP_SOURCE_OPT_DESCR).hasArg().withArgName("bootstrap_source_name")
            .create(BOOTSTRAP_SOURCE_OPT_CHAR);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(actionOption);
    options.addOption(clientPropsOption);
    options.addOption(cp3PropsOption);
    options.addOption(propsPrefixOption);
    options.addOption(sourcesOption);
    options.addOption(scnOptOption);
    options.addOption(sinceScnOptOption);
    options.addOption(startScnOptOption);
    options.addOption(targetScnOptOption);
    options.addOption(typeOption);
    options.addOption(bootstrapSourceOption);

    return options;
}

From source file:com.opengamma.integration.tool.portfolio.PortfolioAggregationTool.java

protected Options createOptions(boolean contextProvided) {
    Options options = super.createOptions(contextProvided);

    @SuppressWarnings("static-access")
    Option baseViewOption = OptionBuilder.withLongOpt("portfolio").hasArg().isRequired()
            .withDescription("The portfolio name").create(PORTFOLIO_OPT);
    options.addOption(baseViewOption);/*from  w  w w  .  j a  v a2  s . c  o  m*/
    @SuppressWarnings("static-access")
    Option aggregationTypesOption = OptionBuilder.withLongOpt("aggregation-types").hasArgs().isRequired()
            .withValueSeparator(',').withDescription("The (comma, no space seperated) names of the aggregation"
                    + " styles to use: e.g AssetClass,Currency,DetailedAssetClass")
            .create(AGGREGATION_OPT);
    options.addOption(aggregationTypesOption);
    @SuppressWarnings("static-access")
    Option splitPortfoliosOption = OptionBuilder.withLongOpt("split")
            .withDescription("Split into separate portfolios grouped by the top-level aggregator"
                    + " instead of aggregating the existing portfoliio")
            .create(SPLIT_OPT);
    options.addOption(splitPortfoliosOption);
    return options;
}

From source file:ComputeNode.java

public static void main(String[] argv) {

    String fileservername = "localhost";
    String id = null;//from  ww w  .j av  a2  s  . c  o  m
    Double underLoad = null;
    Double overLoad = null;
    Double failProb = null;
    Double constantload = null;
    Pair<Double, Double> gaussian = null;
    String fileName = null;

    ArgumentHandler cli = new ArgumentHandler(
            "FileServer [-h] [collector address] [-u underload] "
                    + "[-o overload] [-c constant_load|-g mean variance] " + "[-p fail_prob] [-f configfile]",
            "Bala Subrahmanyam Kambala, Daniel William DaCosta - "
                    + "GPLv3 (http://www.gnu.org/copyleft/gpl.html)",
            "");
    cli.addOption("h", "help", false, "Print this usage information.");
    cli.addOption("u", "underLoad", true, "Under load threshold");
    cli.addOption("o", "overLoad", true, "Over load threshold");
    cli.addOption("c", "constant", true, "Generate constant load");
    cli.addOption("p", "probability", true, "Fail Probability(0-100)");
    cli.addOption("f", "configfile", true,
            "The configuration file to read parameters from. " + "The default is " + defaultconf + ". "
                    + "Command line arguments will override config file " + "arguments.");
    cli.addOption(OptionBuilder.withLongOpt("gaussian").hasArgs(2)
            .withDescription("Generate a gaussian probability model for load "
                    + "simulation. The first parameter is the mean "
                    + "and the second parameter is the variance.")
            .create('g'));

    // parse command line
    CommandLine commandLine = cli.parse(argv);
    if (commandLine.hasOption('h')) {
        cli.usage("");
        System.exit(0);
    }

    if (commandLine.hasOption('u')) {
        // TODO : Ensure the number is within range
        underLoad = Double.parseDouble(commandLine.getOptionValue('u'));
    }

    if (commandLine.hasOption('o')) {
        // TODO : Ensure the number is within range
        overLoad = Double.parseDouble(commandLine.getOptionValue('o'));
    }

    if (commandLine.hasOption('p')) {
        // TODO : Ensure the number is within range
        failProb = Double.parseDouble(commandLine.getOptionValue('p'));
    }

    if (commandLine.hasOption('c')) {
        // TODO : Ensure the number is within range
        constantload = Double.parseDouble(commandLine.getOptionValue('c'));
    }

    if (commandLine.hasOption('g')) {
        // TODO : Ensure the number is within range
        gaussian = new Pair<Double, Double>(Double.parseDouble(commandLine.getOptionValues('g')[0]),
                Double.parseDouble(commandLine.getOptionValues('g')[1]));
    }

    // TODO: If these flags are no longer mutually exclusive this
    // code should be adjusted to account for whatever constraint are
    // needed.
    if ((constantload != null) && (gaussian != null)) {
        cli.usage("-g -c switches are mutually exclusive!\n");
        System.exit(1);
    }

    if (commandLine.hasOption('f')) {
        fileName = commandLine.getOptionValue('f');
    }

    if (commandLine.getArgs().length != 0)
        fileservername = commandLine.getArgs()[0];
    System.out.println(argv);
    try {
        ComputeNode node = new ComputeNode(fileservername, underLoad, overLoad, failProb, constantload,
                gaussian, fileName);

        Naming.rebind("ComputeNode" + Integer.toString(node.getID()), node);

        // Scheduling heart beat message handler
        Timer t = new Timer();
        HeartBeatHandler h = node.new HeartBeatHandler();
        t.schedule(h, 0, 1 * 1000);

    } catch (ConnectException ce) {
        //lg.log(Level.SEVERE, "Server is not alive");
        ce.printStackTrace();
    } catch (Exception e) {
        //lg.log(Level.SEVERE, "Exception in file server");
        e.printStackTrace();
    }
}

From source file:com.linkedin.helix.mock.storage.MockHealthReportParticipant.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  a2s . 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(host).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

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

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("Zookeeper server address(Required)");

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

    return options;
}

From source file:hws.core.ExecutorThread.java

public void run(String[] args) throws IOException, ClassNotFoundException, InstantiationException,
        IllegalAccessException, ParseException {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("app-id").withDescription("String of the Application Id")
            .hasArg().withArgName("AppId").create("aid"));
    options.addOption(OptionBuilder.withLongOpt("container-id").withDescription("String of the Container Id")
            .hasArg().withArgName("ContainerId").create("cid"));
    options.addOption(OptionBuilder.withLongOpt("load").withDescription("load module instance").hasArg()
            .withArgName("Json-Base64").create());
    options.addOption(OptionBuilder.withLongOpt("zk-servers").withDescription("List of the ZooKeeper servers")
            .hasArgs().withArgName("zkAddrs").create("zks"));
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    String appIdStr = null;//from   w  w w  .j  av a  2 s .c  o  m
    String containerIdStr = null;
    String instanceInfoBase64 = null;
    String instanceInfoJson = null;
    InstanceInfo instanceInfo = null;

    if (cmd.hasOption("aid")) {
        appIdStr = cmd.getOptionValue("aid");
    }
    if (cmd.hasOption("cid")) {
        containerIdStr = cmd.getOptionValue("cid");
    }
    String zksArgs = "";
    String[] zkServers = null;
    if (cmd.hasOption("zks")) {
        zksArgs = "-zks";
        zkServers = cmd.getOptionValues("zks");
        for (String zks : zkServers) {
            zksArgs += " " + zks;
        }
    }

    //Logger setup
    Configuration conf = new Configuration();
    FileSystem fileSystem = FileSystem.get(conf);
    FSDataOutputStream writer = fileSystem
            .create(new Path("hdfs:///hws/apps/" + appIdStr + "/logs/" + containerIdStr + ".log"));
    Logger.addOutputStream(writer);

    Logger.info("Processing Instance");

    if (cmd.hasOption("load")) {
        instanceInfoBase64 = cmd.getOptionValue("load");
        instanceInfoJson = StringUtils.newStringUtf8(Base64.decodeBase64(instanceInfoBase64));
        instanceInfo = Json.loads(instanceInfoJson, InstanceInfo.class);
    }

    Logger.info("Instance info: " + instanceInfoJson);

    this.latch = new CountDownLatch(instanceInfo.inputChannels().keySet().size());
    Logger.info("Latch Countdowns: " + instanceInfo.inputChannels().keySet().size());

    ZkClient zk = new ZkClient(zkServers[0]); //TODO select a ZooKeeper server

    Logger.info("Load Instance " + instanceInfo.instanceId());
    loadInstance(instanceInfo, zk, "/hadoop-watershed/" + appIdStr + "/");

    IZkChildListener producersHaltedListener = createProducersHaltedListener();
    String znode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/halted";
    Logger.info("halting znode: " + znode);
    zk.subscribeChildChanges(znode, producersHaltedListener);

    ExecutorService serverExecutor = Executors.newCachedThreadPool();

    //wait for a start command from the ApplicationMaster via ZooKeeper
    znode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/start";
    Logger.info("starting znode: " + znode);
    zk.waitUntilExists(znode, TimeUnit.MILLISECONDS, 250);
    Logger.info("Exists: " + zk.exists(znode));
    /*
    while(!zk.waitUntilExists(znode,TimeUnit.MILLISECONDS, 500)){
       //out.println("TIMEOUT waiting for start znode: "+znode);
       //out.flush();
    }*/
    //start and execute this instance
    Logger.info("Starting Instance");
    startExecutors(serverExecutor);
    Logger.info("Instance STARTED");

    Logger.info("Waiting TERMINATION");

    try {
        this.latch.await(); //await the input threads to finish
    } catch (InterruptedException e) {
        // handle
        Logger.severe("Waiting ERROR: " + e.getMessage());
    }

    Logger.info("Finishing Instance");
    finishExecutors();
    Logger.info("FINISHED Instance " + instanceInfo.instanceId());
    String finishZnode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/finish/"
            + instanceInfo.instanceId();
    zk.createPersistent(finishZnode, "");
}

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.//ww w.j a va2 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// www . ja  va  2s.c  o  m
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:cytoscape.CyMain.java

License:asdf

protected void parseCommandLine(String[] args) {
    // create the options
    options.addOption("h", "help", false, "Print this message.");
    options.addOption("v", "version", false, "Print the version number.");
    // commented out until we actually support doing anything in headless
    // mode//from w w w.j  a  va 2  s .  c  o m
    // options.addOption("H", "headless", false, "Run in headless (no gui)
    // mode.");
    options.addOption(
            OptionBuilder.withLongOpt("session").withDescription("Load a cytoscape session (.cys) file.")
                    .withValueSeparator('\0').withArgName("file").hasArg() // only allow one session!!!
                    .create("s"));

    options.addOption(OptionBuilder.withLongOpt("network").withDescription("Load a network file (any format).")
            .withValueSeparator('\0').withArgName("file").hasArgs().create("N"));

    options.addOption(OptionBuilder.withLongOpt("edge-attrs")
            .withDescription("Load an edge attributes file (edge attribute format).").withValueSeparator('\0')
            .withArgName("file").hasArgs().create("e"));
    options.addOption(OptionBuilder.withLongOpt("node-attrs")
            .withDescription("Load a node attributes file (node attribute format).").withValueSeparator('\0')
            .withArgName("file").hasArgs().create("n"));
    options.addOption(
            OptionBuilder.withLongOpt("matrix").withDescription("Load a node attribute matrix file (table).")
                    .withValueSeparator('\0').withArgName("file").hasArgs().create("m"));

    options.addOption(OptionBuilder.withLongOpt("plugin")
            .withDescription(
                    "Load a plugin jar file, directory of jar files, plugin class name, or plugin jar URL.")
            .withValueSeparator('\0').withArgName("file").hasArgs().create("p"));

    options.addOption(OptionBuilder.withLongOpt("props").withDescription(
            "Load cytoscape properties file (Java properties format) or individual property: -P name=value.")
            .withValueSeparator('\0').withArgName("file").hasArgs().create("P"));
    options.addOption(OptionBuilder.withLongOpt("vizmap")
            .withDescription("Load vizmap properties file (Java properties format).").withValueSeparator('\0')
            .withArgName("file").hasArgs().create("V"));

    // try to parse the cmd line
    CommandLineParser parser = new PosixParser();
    CommandLine line = null;

    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing command line failed: " + e.getMessage());
        printHelp();
        System.exit(1);
    }

    // Read any argument containing ".cys" as session file.
    // Allows session files to be passed in via MIME type settings.
    // This imprecise method is overwritten by -s option, if specified.
    for (String freeArg : args) {
        if (freeArg.contains(".cys")) {
            sessionFile = freeArg;
        }
    }

    // use what is found on the command line to set values
    if (line.hasOption("h")) {
        printHelp();
        System.exit(0);
    }

    if (line.hasOption("v")) {
        CytoscapeVersion version = new CytoscapeVersion();
        logger.info(version.getVersion());
        System.exit(0);
    }

    if (line.hasOption("H")) {
        mode = CyInitParams.TEXT;
    } else {
        mode = CyInitParams.GUI;
        setupLookAndFeel();
    }

    if (line.hasOption("P"))
        props = createProperties(line.getOptionValues("P"));
    else
        props = createProperties(new String[0]);

    if (line.hasOption("N"))
        graphFiles = line.getOptionValues("N");

    if (line.hasOption("p"))
        plugins = line.getOptionValues("p");

    if (line.hasOption("V"))
        vizmapProps = createProperties(line.getOptionValues("V"));
    else
        vizmapProps = createProperties(new String[0]);

    if (line.hasOption("s"))
        sessionFile = line.getOptionValue("s");

    if (line.hasOption("n"))
        nodeAttrFiles = line.getOptionValues("n");

    if (line.hasOption("e"))
        edgeAttrFiles = line.getOptionValues("e");

    if (line.hasOption("m"))
        expressionFiles = line.getOptionValues("m");
}