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:example.HelloConsole.java

public static void main(String[] args) throws Exception {
    Option msg = Option.builder("m").longOpt("message").hasArg().desc("the message to capitalize").build();
    Options options = new Options();
    options.addOption(msg);

    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);

    String message = line.getOptionValue("m", "Hello Ivy!");
    System.out.println("standard message : " + message);
    System.out.println(/*from   w w w. j  a  v a2s . c o  m*/
            "capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message));
}

From source file:ant_ivy.Hello.java

public static void main(String[] args) throws Exception {
    Option msg = OptionBuilder.withArgName("msg").hasArg().withDescription("the message to capitalize")
            .create("message");
    Options options = new Options();
    options.addOption(msg);

    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(options, args);

    String message = line.getOptionValue("message", "hello ivy !");
    System.out.println("standard message : " + message);
    System.out.println(//from  w w w  .  j av a2s .  c o m
            "capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message));
}

From source file:com.cloudera.impala.testutil.SentryServiceWrapper.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    // Parse command line options to get config file path.
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config_file")
            .withDescription("Absolute path to a sentry-site.xml config file").hasArg()
            .withArgName("CONFIG_FILE").isRequired().create('c'));
    BasicParser optionParser = new BasicParser();
    CommandLine cmdArgs = optionParser.parse(options, args);

    SentryServiceWrapper server = new SentryServiceWrapper(
            new SentryConfig(cmdArgs.getOptionValue("config_file")));
    server.start();//w  w w .ja  va 2s .c om
}

From source file:au.id.hazelwood.xmltvguidebuilder.runner.Main.java

public static void main(String[] args) throws Exception {
    SLF4JBridgeHandler.install();//  w ww.ja v a 2 s  .  com

    Options options = new Options();
    options.addOption(createOptionWithArg("config", true, "file", File.class, "Config file location"));
    options.addOption(createOptionWithArg("out", true, "file", File.class, "Output file name"));

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        App app = new App();
        app.run((File) line.getParsedOptionValue("config"), (File) line.getParsedOptionValue("out"));
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Main", options, true);
    }
}

From source file:de.stz.bt.nanopubsub.StandaloneBroker.java

/**
 * Main Method for running the standalone Broker
 * //  w w w .jav  a 2 s .  c o  m
 * @param args
 * @author jseitter
 */
public static void main(String[] args) {

    Options options = new Options();

    options.addOption(
            OptionBuilder.hasArg(true).withArgName("port").withDescription("broker port number").create('p'));

    Parser parser = new PosixParser();
    CommandLine cmdLine = null;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp(options);
    }

    if (cmdLine == null)
        printHelp(options);

    new StandaloneBroker(cmdLine);

}

From source file:io.github.dustalov.maxmax.Application.java

public static void main(String[] args) throws IOException {
    final CommandLineParser parser = new DefaultParser();

    final Options options = new Options();
    options.addOption(Option.builder("in").argName("in").desc("input graph in the ABC format").hasArg()
            .required().build());//ww  w  .ja va2s .  c  o  m
    options.addOption(Option.builder("out").argName("out").desc("name of cluster output file").hasArg()
            .required().build());

    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (final ParseException ex) {
        System.err.println(ex.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar this.jar", options, true);
        System.exit(1);
    }

    final UndirectedGraph<String, DefaultWeightedEdge> graph = parse(cmd.getOptionValue("in"),
            ABCParser::parse);
    final MaxMax<String> maxmax = new MaxMax<>(graph);
    maxmax.run();
    write(cmd.getOptionValue("out"), maxmax);
}

From source file:com.nextdoor.bender.CreateSchema.java

public static void main(String[] args) throws ParseException, InterruptedException, IOException {

    /*//from w ww.  j  a va2  s  .  com
     * Parse cli arguments
     */
    Options options = new Options();
    options.addOption(Option.builder().longOpt("out-file").hasArg()
            .desc("Filename to output schema to. Default: schema.json").build());
    options.addOption(Option.builder().longOpt("docson").hasArg(false)
            .desc("Create a schema that is able to be read by docson").build());
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    String filename = cmd.getOptionValue("out-file", "schema.json");

    /*
     * Write schema
     */
    BenderSchema schema = new BenderSchema();
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    JsonNode node = schema.getSchema();

    if (cmd.hasOption("docson")) {
        modifyNode(node);
    }

    mapper.writeValue(new File(filename), node);
}

From source file:cc.twittertools.index.ExtractTweetidsFromCollection.java

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

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));

    CommandLine cmdline = null;//w  ww  . ja v a  2s  . com
    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(COLLECTION_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractTweetidsFromCollection.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    StatusStream stream = new JsonStatusCorpusReader(file);

    Status status;
    while ((status = stream.next()) != null) {
        System.out.println(status.getId() + "\t" + status.getScreenname());
    }
}

From source file:dyco4j.instrumentation.entry.CLI.java

public static void main(final String[] args) throws IOException {
    final Options _options = new Options();
    _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg()
            .desc("Folder containing the classes (as descendants) to be instrumented.").build());
    _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg()
            .desc("Folder containing the classes (as descendants) with instrumentation.").build());
    final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.",
            METHOD_NAME_REGEX);//from  w  w  w  . j a  va2  s . co m
    _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build());
    _options.addOption(Option.builder().longOpt(ONLY_ANNOTATED_TESTS_OPTION).hasArg(false)
            .desc("Instrument only tests identified by annotations.").build());

    try {
        processCommandLine(new DefaultParser().parse(_options, args));
    } catch (final ParseException _ex) {
        new HelpFormatter().printHelp(CLI.class.getName(), _options);
    }
}

From source file:edu.scripps.fl.pubchem.app.ResultDownloader.java

public static void main(String[] args) throws Exception {
    CommandLineHandler clh = new CommandLineHandler() {
        public void configureOptions(Options options) {
            options.addOption(OptionBuilder.withLongOpt("data_url").withType("").withValueSeparator('=')
                    .hasArg().create());
        }/*from w ww . j a va 2s.  c  o m*/
    };
    args = clh.handle(args);
    String data_url = clh.getCommandLine().getOptionValue("data_url");
    ResultDownloader rd = new ResultDownloader();

    if (data_url != null)
        rd.setDataUrl(new URL(data_url));
    else
        rd.setDataUrl(new URL("ftp://ftp.ncbi.nlm.nih.gov/pubchem/Bioassay/CSV/"));
    if (args.length == 0)
        rd.process();
    else {
        Integer[] list = (Integer[]) ConvertUtils.convert(args, Integer[].class);
        rd.process(((List<Integer>) Arrays.asList(list)).iterator());
    }
}