Example usage for org.apache.commons.cli CommandLine hasOption

List of usage examples for org.apache.commons.cli CommandLine hasOption

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine hasOption.

Prototype

public boolean hasOption(char opt) 

Source Link

Document

Query to see if an option has been set.

Usage

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;/*  www  . ja va 2s  . co  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:com.google.api.codegen.configgen.ConfigGeneratorTool.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  .  jav  a  2 s  .  c om
            Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.")
                    .hasArg().argName("SERVICE-YAML").required(true).build());
    options.addOption(
            Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.")
                    .hasArg().argName("OUTPUT-FILE").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("output"));
}

From source file:com.google.cloud.trace.v1.TraceServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*w  w w  . j ava 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("TraceServiceSmokeTest", 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.google.cloud.pubsub.v1.TopicAdminSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*from  www  . ja  v a  2s.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.google.cloud.monitoring.v3.MetricServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*ww w  . 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("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: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  va  2 s  . c  o 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();
    }

}

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;/*from  w w  w  .j  a  v  a 2 s  .c o 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.adobe.aem.demomachine.Base64Encoder.java

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

    String value = null;/*from w  w  w  .jav a  2 s.c  om*/

    // Command line options for this tool
    Options options = new Options();
    options.addOption("v", true, "Value");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("v")) {
            value = cmd.getOptionValue("v");
        }

        if (value == null) {
            System.out.println("Command line parameters: -v value");
            System.exit(-1);
        }

    } catch (ParseException ex) {

        logger.error(ex.getMessage());

    }

    byte[] encodedBytes = Base64.encodeBase64(value.getBytes());
    System.out.println(new String(encodedBytes));

}

From source file:com.level3.hiper.dyconn.be.Main.java

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

    try {/*ww  w  .j  a  v  a 2  s  . co m*/
        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:fr.iphc.grid.jobmonitor.JobList.java

public static void main(String[] args) throws Exception {
    JobList command = new JobList();
    CommandLine line = command.parse(args);
    if (line.hasOption(OPT_HELP)) {
        command.printHelpAndExit(null);/*from ww w  .ja  va  2  s.  c  om*/
    } else {
        // get arguments
        URL serviceURL = URLFactory.createURL(command.m_nonOptionValues[0]);

        // get status
        Session session = SessionFactory.createSession(true);
        JobService service = JobFactory.createJobService(session, serviceURL);

        // dump list
        List<String> list = service.list();
        for (String jobid : list) {
            System.out.println(jobid);
        }
    }
}