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:find.Main.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();//from w  w w . j  av  a  2 s .  c  o m
    try {

        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse(options, args);
        File dir = new File(line.getOptionValue("dir", "."));
        String name = line.getOptionValue("name", "jar");
        Collection files = FindFile.find(dir, name);
        System.out.println("listing files in " + dir + " containing " + name);
        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("find", options);
    }
}

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

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*from w ww  .ja  va2s .  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.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 w ww .j ava2 s .  c om*/
    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:com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {//from w  ww .ja v  a2  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("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: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 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.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(//w  w  w  .j a va 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 www .j a v  a 2s  . co m*/
            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"));
}

From source file:de.mustnotbenamed.quickstart.undertowserver.Main.java

public static void main(String[] args) {
    CommandLine cmd = null;/*from   w  w w .j  av  a  2s . com*/

    try {
        CommandLineParser parser = new GnuParser();
        cmd = parser.parse(createCliOption(), args);
    } catch (Exception e) {
        System.err.println("Failed to parse options: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("webapp", createCliOption());

        System.err.println("\n");
        System.err.println("### DEV ###");
        e.printStackTrace();

        System.exit(-1);
    }

    // start Webserver
    try {
        UndertowBootstrap.UndertowOptions options = new UndertowBootstrap.UndertowOptions();

        options.setHost(CliHelper.option(cmd, OPTION_HOST, options.getHost()));
        options.setPort(CliHelper.option(cmd, OPTION_PORT, options.getPort()));
        options.setContextPath(CliHelper.option(cmd, OPTION_CONTEXT_PATH, options.getContextPath()));

        new WeldUndertowBootstrap(options).startup();
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.epitech.oliver_f.astextexls.MainClass.java

public static void main(String[] args) {
    initalizeOption();/*  ww w .  j  av  a 2 s  .  c  om*/
    CommandLineParser parser = new BasicParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args);
    } catch (ParseException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (cl != null && cl.hasOption("help")) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    if (cl.hasOption("folder") && cl.hasOption("file")) {
        launchWriteAndRead(cl.getOptionValue("folder"), cl.getOptionValue("file"));
        System.out.println("OK");

    } else {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("astexte script", options);
    }
    launch(args);
}

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;/* ww w  .  j av a2s  . c  om*/
    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());
    }
}