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(String opt, String longOpt, boolean hasArg, String description) 

Source Link

Document

Add an option that contains a short-name and a long-name.

Usage

From source file:com.google.cloud.pubsub.v1.TopicAdminSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*from  w ww .  j  a  v a2s.co  m*/
        Options options = new Options();
        options.addOption("h", "help", false, "show usage");
        options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg()
                .argName("PROJECT-ID").required(true).build());
        CommandLine cl = (new DefaultParser()).parse(options, args);
        if (cl.hasOption("help")) {
            HelpFormatter formater = new HelpFormatter();
            formater.printHelp("TopicAdminSmokeTest", options);
        }
        executeNoCatch(cl.getOptionValue("project_id"));
        System.out.println("OK");
    } catch (Exception e) {
        System.err.println("Failed with exception:");
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:com.opensearchserver.textextractor.Main.java

public static void main(String[] args) throws IOException, ParseException {
    Logger.getLogger("").setLevel(Level.WARNING);
    Options options = new Options();
    options.addOption("h", "help", false, "print this message");
    options.addOption("p", "port", true, "TCP port");
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar target/oss-text-extractor.jar", options);
        return;//from   ww  w . j a  v a 2s  .c o  m
    }
    int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9091;
    UndertowJaxrsServer server = new UndertowJaxrsServer()
            .start(Undertow.builder().addHttpListener(port, "localhost"));
    server.deploy(Main.class);
}

From source file:com.google.cloud.monitoring.v3.MetricServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {//from www .j a  va2 s.c o m
        Options options = new Options();
        options.addOption("h", "help", false, "show usage");
        options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg()
                .argName("PROJECT-ID").required(true).build());
        CommandLine cl = (new DefaultParser()).parse(options, args);
        if (cl.hasOption("help")) {
            HelpFormatter formater = new HelpFormatter();
            formater.printHelp("MetricServiceSmokeTest", options);
        }
        executeNoCatch(cl.getOptionValue("project_id"));
        System.out.println("OK");
    } catch (Exception e) {
        System.err.println("Failed with exception:");
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:com.discursive.jccook.cmdline.CliBasicExample.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    options.addOption("h", "help", false, "Print this usage information");
    options.addOption("v", "verbose", false, "Print out VERBOSE debugging information");
    options.addOption("f", "file", true, "File to save program output to");

    CommandLine commandLine = parser.parse(options, args);

    boolean verbose = false;
    String file = "";

    if (commandLine.hasOption('h')) {
        System.out.println("Help Message");
        System.exit(0);//w  w w.j  a  va 2s.  c  o  m
    }

    if (commandLine.hasOption('v')) {
        verbose = true;
    }

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

    System.exit(0);
}

From source file:com.rapleaf.hank.cli.AddDomainToDomainGroup.java

/**
 * @param args//from  w  ww. j  av  a 2 s .  c o m
 * @throws IOException
 * @throws ParseException
 * @throws NumberFormatException
 * @throws InvalidConfigurationException
 */
public static void main(String[] args)
        throws IOException, ParseException, NumberFormatException, InvalidConfigurationException {
    Options options = new Options();
    options.addOption("g", "domain-group", true, "the name of the domain group");
    options.addOption("d", "domain", true, "the name of the domain to be added to the group");
    options.addOption("i", "id", true, "the id for the domain in this group");
    options.addOption("c", "config", true,
            "path of a valid config file with coordinator connection information");
    try {
        CommandLine line = new GnuParser().parse(options, args);
        CommandLineChecker.check(line, options, new String[] { "config", "domain-group", "domain" },
                AddDomainToDomainGroup.class);
        ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config"));
        addDomainToDomainGroup(configurator, line.getOptionValue("domain-group"), line.getOptionValue("domain"),
                Integer.parseInt(line.getOptionValue("id")));
    } catch (ParseException e) {
        new HelpFormatter().printHelp("add_domain", options);
        throw e;
    }
}

From source file:eu.scape_project.imageio_wrapper.ImageIOCli.java

public static void main(String[] args) {
    try {//from  w ww .jav  a2s . com
        Options options = new Options();
        options.addOption("i", "input-file", true, "input file");
        options.addOption("o", "output-file", true, "output file");

        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("i") && cmd.hasOption("o")) {
            BufferedImage inImage = ImageIOWrapper.load(cmd.getOptionValue("i"), null);
            if (inImage != null) {
                ImageIOWrapper.convert(inImage, cmd.getOptionValue("o"), null);
            } else {
                System.out.println("Unsuported input image file format!");
                System.exit(1);
            }
        } else {
            System.out.println("usage: (-i|--input-file=) INPUT_FILE (-o|--output-file=) OUTPUT_FILE");
            System.exit(1);
        }
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }
    System.exit(0);
}

From source file:com.uber.tchannel.ping.PingServer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("p", "port", true, "Server Port to connect to");
    options.addOption("?", "help", false, "Usage");
    HelpFormatter formatter = new HelpFormatter();

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

    if (cmd.hasOption("?")) {
        formatter.printHelp("PingClient", options, true);
        return;/*from   w ww  .j  a  v  a  2s.c o m*/
    }

    int port = Integer.parseInt(cmd.getOptionValue("p", "8888"));

    System.out.println(String.format("Starting server on port: %d", port));
    new PingServer(port).run();
    System.out.println("Stopping server...");
}

From source file:mosaicsimulation.MosaicLockstepServer.java

public static void main(String[] args) {
    Options opts = new Options();
    opts.addOption("s", "serverPort", true, "Listening TCP port used to initiate handshakes");
    opts.addOption("n", "nClients", true, "Number of clients that will participate in the session");
    opts.addOption("t", "tickrate", true, "Number of transmission session to execute per second");
    opts.addOption("m", "maxUDPPayloadLength", true, "Max number of bytes per UDP packet");
    opts.addOption("c", "connectionTimeout", true, "Timeout for UDP connections");

    DefaultParser parser = new DefaultParser();
    CommandLine commandLine = null;//ww w.ja  v  a  2s.  c o  m
    try {
        commandLine = parser.parse(opts, args);
    } catch (ParseException ex) {
        ex.printStackTrace();
        System.exit(1);
    }

    int serverPort = Integer.parseInt(commandLine.getOptionValue("serverPort"));
    int nClients = Integer.parseInt(commandLine.getOptionValue("nClients"));
    int tickrate = Integer.parseInt(commandLine.getOptionValue("tickrate"));
    int maxUDPPayloadLength = Integer.parseInt(commandLine.getOptionValue("maxUDPPayloadLength"));
    int connectionTimeout = Integer.parseInt(commandLine.getOptionValue("connectionTimeout"));

    Thread serverThread = LockstepServer.builder().clientsNumber(nClients).tcpPort(serverPort)
            .tickrate(tickrate).maxUDPPayloadLength(maxUDPPayloadLength).connectionTimeout(connectionTimeout)
            .build();

    serverThread.setName("Main-server-thread");
    serverThread.start();

    try {
        serverThread.join();
    } catch (InterruptedException ex) {
        LOG.error("Server interrupted while joining");
    }
}

From source file:com.rapleaf.hank.cli.AddDomain.java

public static void main(String[] args)
        throws InterruptedException, ParseException, IOException, InvalidConfigurationException {
    Options options = new Options();
    options.addOption("n", "name", true, "the name of the domain to be created");
    options.addOption("p", "num-parts", true, "the number of partitions for this domain");
    options.addOption("f", "storage-engine-factory", true,
            "class name of the storage engine factory used by this domain");
    options.addOption("o", "storage-engine-options", true,
            "path to a yaml file containing the options for the storage engine");
    options.addOption("t", "partitioner", true, "class name of the partition used by this domain");
    options.addOption("v", "initial-version", true, "initial version number of this domain");
    options.addOption("c", "config", true,
            "path of a valid config file with coordinator connection information");
    try {//from  w  w w.  j a  v  a 2  s .  c  o m
        CommandLine line = new GnuParser().parse(options, args);
        CommandLineChecker.check(line, options, new String[] { "name", "num-parts", "storage-engine-factory",
                "storage-engine-options", "partitioner", "initial-version" }, AddDomain.class);
        Configurator configurator = new YamlClientConfigurator(line.getOptionValue("config"));
        addDomain(configurator, line.getOptionValue("name"), line.getOptionValue("num-parts"),
                line.getOptionValue("storage-engine-factory"), line.getOptionValue("storage-engine-options"),
                line.getOptionValue("partitioner"), line.getOptionValue("initial-version"));
    } catch (ParseException e) {
        new HelpFormatter().printHelp("add_domain", options);
        throw e;
    }
}

From source file:example.ConfigurationsExample.java

public static void main(String[] args) {
    String jdbcPropToLoad = "prod.properties";
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("d", "dev", false,
            "Dev tag to launch app in dev mode. Means that app will launch embedded mckoi db.");
    try {//from  w  w  w  .ja va2 s.co  m
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("d")) {
            System.err.println("App is in DEV mode");
            jdbcPropToLoad = "dev.properties";
        }
    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    }
    Properties p = new Properties();
    try {
        p.load(ConfigurationsExample.class.getResourceAsStream("/" + jdbcPropToLoad));
    } catch (IOException e) {
        System.err.println("Properties loading failed.  Reason: " + e.getMessage());
    }
    try {
        String clazz = p.getProperty("driver.class");
        Class.forName(clazz);
        System.out.println(" Jdbc driver loaded :" + clazz);
    } catch (ClassNotFoundException e) {
        System.err.println("Jdbc Driver class loading failed.  Reason: " + e.getMessage());
        e.printStackTrace();
    }

}