Example usage for org.apache.commons.cli Options addOption

List of usage examples for org.apache.commons.cli Options addOption

Introduction

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

Prototype

public Options addOption(Option opt) 

Source Link

Document

Adds an option instance

Usage

From source file:cc.twittertools.search.api.TrecSearchThriftLoadGenerator.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(HELP_OPTION, "show help"));
    options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION));
    options.addOption(OptionBuilder.withArgName("index").hasArg().withDescription("host").create(HOST_OPTION));
    options.addOption(//from   ww w.j a v  a  2s .  c o  m
            OptionBuilder.withArgName("num").hasArg().withDescription("threads").create(THREADS_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of queries to process")
            .create(LIMIT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(HOST_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(TrecSearchThriftServer.class.getName(), options);
        System.exit(-1);
    }

    String host = cmdline.getOptionValue(HOST_OPTION);
    int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION))
            : DEFAULT_PORT;
    int numThreads = cmdline.hasOption(THREADS_OPTION)
            ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION))
            : DEFAULT_THREADS;
    int limit = cmdline.hasOption(LIMIT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(LIMIT_OPTION))
            : Integer.MAX_VALUE;

    String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null;
    String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null;

    String queryFile = "data/queries.trec2005efficiency.txt";
    new TrecSearchThriftLoadGenerator(new File(queryFile), limit).withThreads(numThreads)
            .withCredentials(group, token).run(host, port);
}

From source file:com.examples.cloud.speech.AsyncRecognizeClient.java

public static void main(String[] args) throws Exception {

    String audioFile = "";
    String host = "speech.googleapis.com";
    Integer port = 443;//from  ww  w. ja  v  a 2s.  c o m
    Integer sampling = 16000;

    CommandLineParser parser = new DefaultParser();

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("uri").withDescription("path to audio uri").hasArg()
            .withArgName("FILE_PATH").create());
    options.addOption(
            OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com")
                    .hasArg().withArgName("ENDPOINT").create());
    options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg()
            .withArgName("PORT").create());
    options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000")
            .hasArg().withArgName("RATE").create());

    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("uri")) {
            audioFile = line.getOptionValue("uri");
        } else {
            System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw).");
            System.exit(1);
        }

        if (line.hasOption("host")) {
            host = line.getOptionValue("host");
        } else {
            System.err.println("An API enpoint must be specified (typically speech.googleapis.com).");
            System.exit(1);
        }

        if (line.hasOption("port")) {
            port = Integer.parseInt(line.getOptionValue("port"));
        } else {
            System.err.println("An SSL port must be specified (typically 443).");
            System.exit(1);
        }

        if (line.hasOption("sampling")) {
            sampling = Integer.parseInt(line.getOptionValue("sampling"));
        } else {
            System.err.println("An Audio sampling rate must be specified.");
            System.exit(1);
        }
    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        System.exit(1);
    }

    ManagedChannel channel = AsyncRecognizeClient.createChannel(host, port);

    AsyncRecognizeClient client = new AsyncRecognizeClient(channel, URI.create(audioFile), sampling);
    try {
        client.recognize();
    } finally {
        client.shutdown();
    }
}

From source file:com.genentech.chemistry.openEye.apps.SDFRingSystemExtractor.java

/**
 * @param args//from www . j av  a  2s.c  o  m
 */
public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option(OPT_INFILE, true, "input file oe-supported");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String inFile = cmd.getOptionValue(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);
    SDFRingSystemExtractor extractor = new SDFRingSystemExtractor(outFile);
    extractor.run(inFile);
    extractor.close();
}

From source file:com.act.biointerpretation.sarinference.ProductScorer.java

public static void main(String[] args) throws Exception {

    // Build command line parser.
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());
    }/*  w ww .  j  a  va2  s.co  m*/
    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        LOGGER.error("Argument parsing failed: %s", e.getMessage());
        HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    File inputCorpusFile = new File(cl.getOptionValue(OPTION_PREDICTION_CORPUS));
    File lcmsFile = new File(cl.getOptionValue(OPTION_LCMS_RESULTS));
    File scoredSarsFile = new File(cl.getOptionValue(OPTION_SCORED_SARS));
    File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_PATH));

    JavaRunnable productScoreRunner = getProductScorer(inputCorpusFile, scoredSarsFile, lcmsFile, outputFile);

    LOGGER.info("Scoring products.");
    productScoreRunner.run();
    LOGGER.info("Complete!.");
}

From source file:edu.upc.eetac.dsa.exercices.java.lang.exceptions.App.java

public static void main(String[] args) throws FileNotFoundException {
    String filename = null;/*from  w  ww.  j a  v a 2  s . c  om*/
    String maxInteger = null;

    Options options = new Options();
    Option optionFile = OptionBuilder.withArgName("file").hasArg().withDescription("file with integers")
            .withLongOpt("file").create("f");
    options.addOption(optionFile);
    Option optionMax = OptionBuilder.withArgName("max").hasArg()
            .withDescription("maximum integer allowed in the file").withLongOpt("max").create("M");
    options.addOption(optionFile);
    options.addOption(optionMax);

    options.addOption("h", "help", false, "prints this message");

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
        if (line.hasOption("h")) { // No hace falta preguntar por el parmetro "help". Ambos son sinnimos
            new HelpFormatter().printHelp(App.class.getCanonicalName(), options);
            return;
        }
        filename = line.getOptionValue("f");
        if (filename == null) {
            throw new org.apache.commons.cli.ParseException(
                    "You must provide the path to the file with numbers.");
        }
        maxInteger = line.getOptionValue("M");
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        new HelpFormatter().printHelp(App.class.getCanonicalName(), options);
        return;
    }

    try {
        int[] numbers = (maxInteger != null) ? FileNumberReader.readFile(filename, Integer.parseInt(maxInteger))
                : FileNumberReader.readFile(filename);
        for (int i = 0; i < numbers.length; i++) {
            System.out.println("Integer read: " + numbers[i]);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BigNumberException e) {
        e.printStackTrace();
    }
}

From source file:net.robyf.dbpatcher.Launcher.java

public static void main(final String[] args) throws DBPatcherException { //NOSONAR
    Options options = new Options();

    Option usernameOption = new Option("u", "username", true, "Database username");
    usernameOption.setRequired(true);//  w w w  .  java 2  s.c  o m
    options.addOption(usernameOption);
    Option passwordOption = new Option("p", "password", true, "Database password");
    passwordOption.setRequired(true);
    options.addOption(passwordOption);
    Option databaseOption = new Option("d", "databaseName", true, "Database name");
    databaseOption.setRequired(true);
    options.addOption(databaseOption);
    options.addOption("r", "rollback-if-error", false, "Rolls back the entire operation in case of errors");
    options.addOption("v", "to-version", true, "Target version number");
    options.addOption("s", "simulation", false, "Simulate the operation without touching the current database");
    options.addOption("c", "character-set", true, "Character set (default value: ISO-8859-1)");

    Parameters parameters = new Parameters();
    boolean showHelp = false;
    try {
        CommandLine commandLine = new PosixParser().parse(options, args);

        parameters.setUsername(commandLine.getOptionValue("u"));
        parameters.setPassword(commandLine.getOptionValue("p"));
        parameters.setDatabaseName(commandLine.getOptionValue("d"));

        parameters.setRollbackIfError(commandLine.hasOption("r"));
        parameters.setSimulationMode(commandLine.hasOption("s"));
        if (commandLine.hasOption("v")) {
            parameters.setTargetVersion(new Long(commandLine.getOptionValue("v")));
        }
        if (commandLine.hasOption("c")) {
            parameters.setCharset(Charset.forName(commandLine.getOptionValue("c")));
        }

        if (commandLine.getArgs().length == 1) {
            parameters.setSchemaPath(commandLine.getArgs()[0]);
        } else {
            showHelp = true;
        }
    } catch (ParseException pe) {
        showHelp = true;
    }

    if (showHelp) {
        new HelpFormatter().printHelp("java -jar dbpatcher.jar" + " -u username -p password -d database_name"
                + " [options] schema_root", "Available options:", options, "");
    } else {
        DBPatcherFactory.getDBPatcher().patch(parameters);
    }
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.evaluation.CouchDbExport.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("host")
            .withDescription("(optional) The couchdb host. default: 127.0.0.1").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("port")
            .withDescription("(optional) The couchdb port. default: 5984").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("username")
            .withDescription("(optional) The couchdb username. default: <empty>").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("password")
            .withDescription("(optional) The couchdb password. default: <empty>").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("dbname")
            .withDescription("(optional) The couchdb database name. default: noun_decompounding").hasArg()
            .create());/* w ww.jav  a 2  s  . com*/
    options.addOption(OptionBuilder.withLongOpt("limit")
            .withDescription("(optional) The amount of documents you want to export. default: all").hasArg()
            .create());

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("countTotalFreq", options);
        return;
    }
    String host = (cmd.hasOption("host")) ? cmd.getOptionValue("host") : "127.0.0.1";
    int port = Integer.parseInt((cmd.hasOption("port")) ? cmd.getOptionValue("port") : "5984");
    String username = (cmd.hasOption("username")) ? cmd.getOptionValue("username") : "";
    String password = (cmd.hasOption("password")) ? cmd.getOptionValue("password") : "";
    String dbName = (cmd.hasOption("dbname")) ? cmd.getOptionValue("dbname") : "";
    int limit = (cmd.hasOption("limit")) ? Integer.parseInt(cmd.getOptionValue("limit")) : Integer.MAX_VALUE;

    IDictionary dict = new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"),
            new File("src/main/resources/de_DE.aff"));
    LinkingMorphemes morphemes = new LinkingMorphemes(new File("src/main/resources/linkingMorphemes.txt"));
    LeftToRightSplitAlgorithm algo = new LeftToRightSplitAlgorithm(dict, morphemes);

    HttpClient httpClient = new StdHttpClient.Builder().host(host).port(port).username(username)
            .password(password).build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    CouchDbConnector db = new StdCouchDbConnector(dbName, dbInstance);

    try {
        CouchDbExport exporter = new CouchDbExport(
                new CcorpusReader(new File("src/main/resources/evaluation/ccorpus.txt")), db);
        exporter.export(algo, limit);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

From source file:com.act.biointerpretation.analytics.ReactionCountProvenance.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());
    }//ww  w  .  j a va2  s . c o m

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        LOGGER.error(String.format("Argument parsing failed: %s\n", e.getMessage()));
        HELP_FORMATTER.printHelp(ReactionCountProvenance.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(ReactionCountProvenance.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        return;
    }

    if (!cl.hasOption(OPTION_OUTPUT_PREFIX)) {
        LOGGER.error("Input -o prefix");
        return;
    }

    List<String> dbs = new ArrayList<>(Arrays.asList(cl.getOptionValues(OPTION_ORDERED_LIST_OF_DBS)));
    ReactionCountProvenance reactionCountProvenance = new ReactionCountProvenance(dbs,
            cl.getOptionValue(OPTION_OUTPUT_PREFIX));
    reactionCountProvenance.run();
    reactionCountProvenance.writeToDisk();
}

From source file:com.act.biointerpretation.analytics.ReactionDeletion.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());
    }//from  ww w . jav a2 s. c om

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        LOGGER.error(String.format("Argument parsing failed: %s\n", e.getMessage()));
        HELP_FORMATTER.printHelp(ReactionCountProvenance.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(ReactionCountProvenance.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        return;
    }

    if (!cl.hasOption(OPTION_OUTPUT_PATH)) {
        LOGGER.error("Input -o prefix");
        return;
    }

    NoSQLAPI srcApi = new NoSQLAPI(cl.getOptionValue(OPTION_SOURCE_DB), cl.getOptionValue(OPTION_SOURCE_DB));
    NoSQLAPI sinkApi = new NoSQLAPI(cl.getOptionValue(OPTION_SINK_DB), cl.getOptionValue(OPTION_SINK_DB));

    searchForDroppedReactions(srcApi, sinkApi, new File(cl.getOptionValue(OPTION_OUTPUT_PATH)));
}

From source file:com.act.lcms.v2.TraceIndexAnalyzer.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());
    }/*from w ww  .  ja v  a  2s. c  o m*/

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        System.err.format("Argument parsing failed: %s\n", e.getMessage());
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    File rocksDBFile = new File(cl.getOptionValue(OPTION_INDEX_PATH));
    if (!rocksDBFile.exists()) {
        System.err.format("Index file at %s does not exist, nothing to analyze", rocksDBFile.getAbsolutePath());
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    LOGGER.info("Starting analysis");

    TraceIndexAnalyzer analyzer = new TraceIndexAnalyzer();
    analyzer.runExtraction(rocksDBFile, new File(cl.getOptionValue(OPTION_OUTPUT_PATH)));

    LOGGER.info("Done");
}