Example usage for org.apache.commons.cli HelpFormatter printHelp

List of usage examples for org.apache.commons.cli HelpFormatter printHelp

Introduction

In this page you can find the example usage for org.apache.commons.cli HelpFormatter printHelp.

Prototype

public void printHelp(String cmdLineSyntax, Options options) 

Source Link

Document

Print the help for options with the specified command line syntax.

Usage

From source file:com.google.api.codegen.config.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(/*  w ww. j  a v  a  2s  . com*/
            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.getOptionValue("output"));
}

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  ww  .  j  av  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:it.anyplace.sync.relay.server.Main.java

public static void main(String[] args) throws ParseException, Exception {
    Options options = new Options();
    options.addOption("r", "relay-server", true, "set relay server to serve for");
    options.addOption("p", "port", true, "set http server port");
    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. ja  v a  2 s .  co  m
    }
    int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 22080;
    String relayServer = firstNonNull(emptyToNull(cmd.getOptionValue("r")), "relay://localhost");
    logger.info("starting http relay server :{} for relay server {}", port, relayServer);
    HttpRelayServer httpRelayServer = new HttpRelayServer(
            DeviceAddress.newBuilder().setDeviceId("relay").setAddress(relayServer).build().getSocketAddress());
    httpRelayServer.start(port);
    httpRelayServer.join();
}

From source file:com.ibm.rdf.store.sparql11.DB2RDFQuery.java

public static void main(String[] args) {
    Options options = new Options();

    try {//from w  w  w  . ja va  2s.  co  m
        // create Options object
        options.addOption("jdbcurl", true, "jdbc url");
        options.addOption("schema", true, "schema name");
        options.addOption("kb", true, "knowledge base");
        options.addOption("username", true, "db user name");
        options.addOption("password", true, "db password");
        options.addOption("queryFile", true, "query file");
        options.addOption("defaultUnionGraph", false, "default Union Graph semantics");

        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);
        boolean defUnion = cmd.hasOption("defaultUnionGraph")
                ? Boolean.parseBoolean(cmd.getOptionValue("defaultUnionGraph"))
                : false;
        DB2TestData data = new DB2TestData(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("kb"),
                cmd.getOptionValue("username"), cmd.getOptionValue("password"),
                cmd.getOptionValue("schemaName"), defUnion);

        DB2RDFQuery q = new DB2RDFQuery(new DB2Engine(), data);
        q.executeQuery(cmd.getOptionValue("queryFile"));
    } catch (Exception e) {
        e.printStackTrace();
        HelpFormatter help = new HelpFormatter();
        help.printHelp("DB2RDFQuery", options);
    }
}

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 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("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 w  w w . j a va 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("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  va  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: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;/*  ww w.ja va 2 s .  co 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:list.Main.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();//from w  ww  . j  ava  2s .co m
    try {

        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse(options, args);
        File dir = new File(line.getOptionValue("dir", "."));
        Collection files = ListFile.list(dir);
        System.out.println("listing files in " + dir);
        for (Iterator it = files.iterator(); it.hasNext();) {
            System.out.println("\t" + it.next() + "\n");
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("list", options);
    }
}

From source file:com.amit.api.compiler.App.java

public static void main(String[] args) {
    Options options = createOptions();//w  w  w. j ava  2  s.  co m

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine cmd = parser.parse(options, args);
        execute(cmd);
    } catch (ParseException exp) {
        System.out.println("Invalid arguments.  Reason: " + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("args", options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}