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:de.dknapps.pswgendesktop.main.PswGenDesktop.java

/**
 * Hier werden die Kommandozeilenparameter analysiert und die Anwendung gestartet.
 *///from   w  w  w. j  av  a  2s. c om
public static void main(String[] args) throws IOException {
    Options options = new Options();
    Option help = new Option("help", "print this message");
    @SuppressWarnings("static-access")
    Option services = OptionBuilder.withArgName("file").hasArg()
            .withDescription("use given file to store services").create("services");
    @SuppressWarnings("static-access")
    Option upgrade = OptionBuilder.withArgName("passphrase").hasArg()
            .withDescription("converts and re-encrypts services to new format if not too old")
            .create("upgrade");
    options.addOption(help);
    options.addOption(services);
    options.addOption(upgrade);
    CommandLineParser parser = new GnuParser(); // GnuParser => mehrbuchstabige Optionen
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage()); // line bleibt null, dann kommt die Hilfe
    }
    if (line == null || line.hasOption("help")) { // Hilfe ausgeben => nur das tun
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("pswgen", options);
    } else if (line.hasOption("upgrade")) { // Datei umformatieren => nur das tun
        String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME);
        String passphrase = line.getOptionValue("upgrade");
        PswGenCtl ctl = new PswGenCtl(servicesFilename);
        ctl.upgradeServiceInfoList(passphrase);
    } else {
        String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME);
        PswGenCtl ctl = new PswGenCtl(servicesFilename);
        ctl.start(); // Anwendung starten, PswGenCtl terminiert die VM
    }
}

From source file:com.basingwerk.utilisation.Utilisation.java

public static void main(final String[] args) {
    String dataFile = null;/*from ww w  . j  a  v  a 2  s.  c o  m*/

    Options options = new Options();

    Option helpOption = new Option("h", "help", false, "print this help");
    Option serverURLOption = new Option("l", "logfile", true, "log file");

    options.addOption(helpOption);
    options.addOption(serverURLOption);

    CommandLineParser argsParser = new PosixParser();

    try {
        CommandLine commandLine = argsParser.parse(options, args);

        if (commandLine.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

        dataFile = commandLine.getOptionValue(serverURLOption.getOpt());
        String[] otherArgs = commandLine.getArgs();

        if (dataFile == null || otherArgs.length > 1) {
            System.out.println("Please specify a logfile");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
    }

    final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:com.opensearchserver.affinities.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("d", "datadir", true, "Data directory");
    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-affinities.jar", options);
        return;//  w ww  .j a va 2s. com
    }
    int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092;

    File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities");
    if (cmd.hasOption("d"))
        dataDir = new File(cmd.getOptionValue("d"));
    if (!dataDir.exists())
        throw new IOException("The data directory does not exists: " + dataDir);
    if (!dataDir.isDirectory())
        throw new IOException("The data directory path is not a directory: " + dataDir);
    AffinityList.load(dataDir);

    UndertowJaxrsServer server = new UndertowJaxrsServer()
            .start(Undertow.builder().addHttpListener(port, "0.0.0.0"));
    server.deploy(Main.class);
}

From source file:com.google.api.codegen.CodeGeneratorTool.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  w  w  .  ja v  a2s  .  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().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.")
            .hasArg().argName("GAPIC-YAML").required(true).build());
    options.addOption(Option.builder().longOpt("package_yaml")
            .desc("The package metadata YAML configuration file.").hasArg().argName("PACKAGE-YAML").build());
    options.addOption(Option.builder("o").longOpt("output")
            .desc("The directory in which to output the generated client library.").hasArg()
            .argName("OUTPUT-DIRECTORY").build());
    options.addOption(Option.builder().longOpt("enabled_artifacts")
            .desc("Optional. Artifacts enabled for the generator. "
                    + "Currently supports 'surface' and 'test'.")
            .hasArg().argName("ENABLED_ARTIFACTS").required(false).build());

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

    int exitCode = generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"),
            cl.getOptionValues("gapic_yaml"), cl.getOptionValue("package_yaml"),
            cl.getOptionValue("output", ""), cl.getOptionValues("enabled_artifacts"));
    System.exit(exitCode);
}

From source file:info.jejking.opengeodb.neo4j.importer.ImporterRunner.java

/**
 * Runs the importer.//from w  w w.j  a v  a  2 s  .c o  m
 * 
 * <p>
 * Supply the following arguments:
 * </p>
 * <ol>
 * <li>path to the tab-delimited place file</li>
 * <li>path to the tab-delimited postal code file</li>
 * <li>path to the directory where the Graph DB is to be found/created</li>
 * </ol>
 * 
 * @param args
 *            as above
 * @throws IOException
 * @throws ParseException 
 */
public static void main(String[] args) throws IOException, ParseException {

    initOptions();

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

    if (commandLine.hasOption("h")) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("opengeodb2neo4j", options);
    } else {
        String placeFilePath = commandLine.getOptionValue("p");
        String zipFilePath = commandLine.getOptionValue("z");
        String neo4jDirPath = commandLine.getOptionValue("n");
        Importer importer = new Importer();
        importer.doImport(placeFilePath, zipFilePath, neo4jDirPath);
    }

}

From source file:com.github.zerkseez.codegen.wrappergenerator.Main.java

public static void main(final String[] args) throws Exception {
    final Options options = new Options();
    options.addOption(Option.builder().longOpt("outputDirectory").hasArg().required().build());
    options.addOption(Option.builder().longOpt("classMappings").hasArgs().required().build());

    final CommandLineParser parser = new DefaultParser();

    try {//from w w w . j  a  v  a  2 s  .  co  m
        final CommandLine line = parser.parse(options, args);
        final String outputDirectory = line.getOptionValue("outputDirectory");
        final String[] classMappings = line.getOptionValues("classMappings");
        for (String classMapping : classMappings) {
            final String[] tokens = classMapping.split(":");
            if (tokens.length != 2) {
                throw new IllegalArgumentException(
                        String.format("Invalid class mapping format \"%s\"", classMapping));
            }
            final Class<?> wrappeeClass = Class.forName(tokens[0]);
            final String fullWrapperClassName = tokens[1];
            final int indexOfLastDot = fullWrapperClassName.lastIndexOf('.');
            final String wrapperPackageName = (indexOfLastDot == -1) ? ""
                    : fullWrapperClassName.substring(0, indexOfLastDot);
            final String simpleWrapperClassName = (indexOfLastDot == -1) ? fullWrapperClassName
                    : fullWrapperClassName.substring(indexOfLastDot + 1);

            System.out.println(String.format("Generating wrapper class for %s...", wrappeeClass));
            final WrapperGenerator generator = new WrapperGenerator(wrappeeClass, wrapperPackageName,
                    simpleWrapperClassName);
            generator.writeTo(outputDirectory, true);
        }
        System.out.println("Done");
    } catch (MissingOptionException e) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(String.format("java -cp CLASSPATH %s", Main.class.getName()), options);
    }
}

From source file:com.mozilla.bagheera.consumer.KafkaLoggerConsumer.java

public static void main(String[] args) {
    OptionFactory optFactory = OptionFactory.getInstance();
    Options options = KafkaConsumer.getOptions();
    options.addOption(optFactory.create("lv", "logvalues", false, "Log values."));

    CommandLineParser parser = new GnuParser();
    ShutdownHook sh = ShutdownHook.getInstance();
    try {/*from  w w  w.j  av a 2s.co m*/
        // Parse command line options
        CommandLine cmd = parser.parse(options, args);

        final KafkaConsumer consumer = KafkaConsumer.fromOptions(cmd);
        sh.addFirst(consumer);

        // Create a sink for storing data
        SinkConfiguration sinkConfig = new SinkConfiguration();
        sinkConfig.setBoolean("loggersink.logvalues", cmd.hasOption("logvalues"));
        KeyValueSinkFactory sinkFactory = KeyValueSinkFactory.getInstance(LoggerSink.class, sinkConfig);
        sh.addLast(sinkFactory);

        // Set the sink for consumer storage
        consumer.setSinkFactory(sinkFactory);

        prepareHealthChecks();

        // Initialize metrics collection, reporting, etc.
        final MetricsManager manager = MetricsManager.getDefaultMetricsManager();

        // Begin polling
        consumer.poll();
    } catch (ParseException e) {
        LOG.error("Error parsing command line options", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(KafkaHBaseConsumer.class.getName(), options);
    }
}

From source file:cc.wikitools.lucene.FindWikipediaArticleId.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(/*from w  w  w  .  j  a  v a 2  s.c  o  m*/
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION));

    CommandLine cmdline = null;
    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(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(FindWikipediaArticleId.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    String title = cmdline.getOptionValue(TITLE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    WikipediaSearcher searcher = new WikipediaSearcher(indexLocation);
    int id = searcher.getArticleId(title);

    out.println(title + ": id = " + id);

    searcher.close();
    out.close();
}

From source file:edu.usc.pgroup.floe.client.commands.KillApp.java

/**
 * Entry point for Scale command./*from w  w w .  j a v  a 2s. c  o m*/
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    options.addOption(appOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String app = line.getOptionValue("app");

    LOGGER.info("Application: {}", app);

    try {
        FloeClient.getInstance().killApp(app);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:cc.twittertools.index.ExtractTweetidsFromIndex.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(/*from  w  w  w  .ja v a 2s.co  m*/
            OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION));

    CommandLine cmdline = null;
    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(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractTweetidsFromIndex.class.getName(), options);
        System.exit(-1);
    }

    File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION));
    if (!indexLocation.exists()) {
        System.err.println("Error: " + indexLocation + " does not exist!");
        System.exit(-1);
    }

    IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation));
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    for (int i = 0; i < reader.maxDoc(); i++) {
        Document doc = reader.document(i);
        out.println(doc.getField(StatusField.ID.name).stringValue() + "\t"
                + doc.getField(StatusField.SCREEN_NAME.name).stringValue());
    }
    out.close();
    reader.close();
}