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.aerospike.client.rest.AerospikeRESTfulService.java

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

    Options options = new Options();
    options.addOption("h", "host", true, "Server hostname (default: localhost)");
    options.addOption("p", "port", true, "Server port (default: 3000)");

    // parse the command line args
    CommandLineParser parser = new PosixParser();
    CommandLine cl = parser.parse(options, args, false);

    // set properties
    Properties as = System.getProperties();
    String host = cl.getOptionValue("h", "localhost");
    as.put("seedHost", host);
    String portString = cl.getOptionValue("p", "3000");
    as.put("port", portString);

    // start app/*from   w w w .j  a v  a2 s . c o m*/
    SpringApplication.run(AerospikeRESTfulService.class, args);

}

From source file:com.google.cloud.logging.v2.LoggingSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/* w ww .j a v  a 2  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("LoggingSmokeTest", 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.SomeApp.java

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

    // Create a Parser
    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 information");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("file").withLongOpt("file").create('f'));
    optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("email").withLongOpt("email").create('m'));
    options.addOptionGroup(optionGroup);

    // Parse the program arguments
    try {//w w w. ja v a2 s.  co  m
        CommandLine commandLine = parser.parse(options, args);

        if (commandLine.hasOption('h')) {
            printUsage(options);
            System.exit(0);
        }

        // ... do important stuff ...
    } catch (Exception e) {
        System.out.println("You provided bad program arguments!");
        printUsage(options);
        System.exit(1);
    }
}

From source file:com.google.api.codegen.DiscoveryFragmentGeneratorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(Option.builder().longOpt("discovery_doc")
            .desc("The Discovery doc representing the service description.").hasArg().argName("DISCOVERY-DOC")
            .required(true).build());//from  www . j  a  v a2 s  .  c  o m
    options.addOption(Option.builder().longOpt("overrides").desc("The path to the sample config overrides file")
            .hasArg().argName("OVERRIDES").build());
    options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.")
            .hasArg().argName("GAPIC-YAML").required(true).build());
    options.addOption(Option.builder("o").longOpt("output")
            .desc("The directory in which to output the generated fragments.").hasArg()
            .argName("OUTPUT-DIRECTORY").build());
    options.addOption(Option.builder().longOpt("auth_instructions")
            .desc("An @-delimited map of language to auth instructions URL: lang:URL@lang:URL@...").hasArg()
            .argName("AUTH-INSTRUCTIONS").build());

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formater = new HelpFormatter();
        formater.printHelp("CodeGeneratorTool", options);
    }

    generate(cl.getOptionValue("discovery_doc"), cl.getOptionValues("gapic_yaml"),
            cl.getOptionValue("overrides", ""), cl.getOptionValue("output", ""),
            cl.getOptionValue("auth_instructions", ""));
}

From source file:it.anyplace.sync.webclient.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("C", "set-config", true, "set config file for s-client");
    options.addOption("h", "help", false, "print help");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("s-client", options);
        return;/*  w  ww  . j  a  va  2s . co m*/
    }

    File configFile = cmd.hasOption("C") ? new File(cmd.getOptionValue("C"))
            : new File(System.getProperty("user.home"), ".s-client.properties");
    logger.info("using config file = {}", configFile);
    try (ConfigurationService configuration = ConfigurationService.newLoader().loadFrom(configFile)) {
        FileUtils.cleanDirectory(configuration.getTemp());
        KeystoreHandler.newLoader().loadAndStore(configuration);
        logger.debug("{}", configuration.getStorageInfo().dumpAvailableSpace());
        try (HttpService httpService = new HttpService(configuration)) {
            httpService.start();
            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().browse(
                        URI.create("http://localhost:" + httpService.getPort() + "/web/webclient.html"));
            }
            httpService.join();
        }
    }
}

From source file:com.discursive.jccook.cmdline.CliComplexExample.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");
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(OptionBuilder.hasArg(true).create('f'));
    optionGroup.addOption(OptionBuilder.hasArg(true).create('m'));
    options.addOptionGroup(optionGroup);

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

    boolean verbose = false;
    String file = "";
    String mail = "";

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

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

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

    System.exit(0);
}

From source file:com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {//from  ww w  .  j ava 2s.c om
        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("ReportErrorsServiceSmokeTest", 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.level3.hiper.dyconn.be.Main.java

public static void main(String... args) {

    try {//from   w w w  .j  a v a 2 s.  c  om
        String bootstrap = "/dyconn-be-toml.cfg";
        CommandLineParser parser = new DefaultParser();
        Options options = new Options();
        options.addOption("c", "config-file", true, "configuration for hapi dyconn module");
        try {
            CommandLine line = parser.parse(options, args);
            if (line.hasOption("config-file")) {
                bootstrap = line.getOptionValue("config-file");
            }
        } catch (ParseException ex) {
            log.error("command line", ex);
            return;
        }

        // read config file
        log.info("loading configuration");
        Config.instance().initialize(bootstrap);

        // initialize queue subsystem
        log.info("initializing messaging");
        Broker.instance().initialize();

        // initilaize persistence
        log.info("starting exector");
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(new MsgReceiver());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.google.api.codegen.SynchronizerTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(//from www. j a v  a 2  s. c o m
            Option.builder().longOpt("source_path").desc("The directory which contains the final code.")
                    .hasArg().argName("SOURCE-PATH").required(true).build());
    options.addOption(
            Option.builder().longOpt("generated_path").desc("The directory which contains the generated code.")
                    .hasArg().argName("GENERATED-PATH").build());
    options.addOption(Option.builder().longOpt("baseline_path")
            .desc("The directory which contains the baseline code.").hasArg().argName("BASELINE-PATH").build());
    options.addOption(Option.builder().longOpt("auto_merge")
            .desc("If set, no GUI will be launched if merge can be completed automatically.")
            .argName("AUTO-MERGE").build());
    options.addOption(Option.builder().longOpt("auto_resolve")
            .desc("Whether to enable smart conflict resolution").argName("AUTO_RESOLVE").build());
    options.addOption(Option.builder().longOpt("ignore_base")
            .desc("If true, the baseline will be ignored and two-way merge will be used.")
            .argName("IGNORE_BASE").build());

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formater = new HelpFormatter();
        formater.printHelp("CodeGeneratorTool", options);
    }

    synchronize(cl.getOptionValue("source_path"), cl.getOptionValue("generated_path"),
            cl.getOptionValue("baseline_path"), cl.hasOption("auto_merge"), cl.hasOption("auto_resolve"),
            cl.hasOption("ignore_base"));
}

From source file:com.google.api.codegen.grpcmetadatagen.GrpcMetadataGeneratorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(Option.builder().longOpt("descriptor_set")
            .desc("The descriptor set representing the compiled input protos.").hasArg()
            .argName("DESCRIPTOR-SET").required(true).build());
    options.addOption(/*from   w w w .  ja va2s  .  com*/
            Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.")
                    .hasArg().argName("SERVICE-YAML").required(true).build());
    options.addOption(
            Option.builder("i").longOpt("input").desc("The input directory containing the gRPC package.")
                    .hasArg().argName("INPUT-DIR").required(true).build());
    options.addOption(
            Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.")
                    .hasArg().argName("OUTPUT-DIR").required(true).build());
    options.addOption(
            Option.builder("l").longOpt("language").desc("The language for which to generate package metadata.")
                    .hasArg().argName("LANGUAGE").required(true).build());
    options.addOption(Option.builder("c").longOpt("metadata_config")
            .desc("The YAML file configuring the package metadata.").hasArg().argName("METADATA-CONFIG")
            .required(true).build());

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formater = new HelpFormatter();
        formater.printHelp("ConfigGeneratorTool", options);
    }

    generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"),
            cl.getOptionValue("input"), cl.getOptionValue("output"), cl.getOptionValue("language"),
            cl.getOptionValue("metadata_config"));
}