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:gov.nasa.jpl.mudrod.xsd2owl.Mapper.java

/**
 * @param args//from   w  ww.  j ava 2s.  c o m
 */
public static void main(String[] args) {
    Option sOpt = Option.builder().hasArg(true).numberOfArgs(1).argName("file").required(false)
            .longOpt(INPUTFILE).desc("A path to a local XSD file.").build();

    Options opts = new Options();
    opts.addOption(sOpt);

    DefaultParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(opts, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Mapper.class.getSimpleName(), opts);
        System.exit(-1);
    }
    File file = null;
    if (cmd.hasOption(INPUTFILE)) {
        try {
            is = new FileInputStream(cmd.getOptionValue(INPUTFILE));
            //file = new File(cmd.getOptionValue(INPUTFILE));
        } catch (FileNotFoundException e) {
            LOG.error("Error processing input XSD from path: {}", e);
        }
    }
    Mapper mapper = new Mapper();
    mapper.executeMapping(is);
}

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

public static void main(String[] args) {
    OptionFactory optFactory = OptionFactory.getInstance();
    Options options = KafkaConsumer.getOptions();
    options.addOption(optFactory.create("o", "output", true, "HDFS base path for output."));
    options.addOption(optFactory.create("df", "dateformat", true, "Date format for the date subdirectories."));
    options.addOption(optFactory.create("fs", "filesize", true, "Max file size for output files."));
    options.addOption(/*from   w w  w .j av a2 s  . c om*/
            optFactory.create("b", "usebytes", false, "Use BytesWritable for value rather than Text."));
    options.addOption(optFactory.create("ts", "addtimestamp", false, "Adds bagheera timestamp to the json"));

    CommandLineParser parser = new GnuParser();
    ShutdownHook sh = ShutdownHook.getInstance();
    try {
        // 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.setString("hdfssink.hdfs.basedir.path", cmd.getOptionValue("output", "/bagheera"));
        sinkConfig.setString("hdfssink.hdfs.date.format", cmd.getOptionValue("dateformat", "yyyy-MM-dd"));
        sinkConfig.setLong("hdfssink.hdfs.max.filesize",
                Long.parseLong(cmd.getOptionValue("filesize", "536870912")));
        sinkConfig.setBoolean("hdfssink.hdfs.usebytes", cmd.hasOption("usebytes"));
        sinkConfig.setBoolean("hdfssink.hdfs.addtimestamp", cmd.hasOption("addtimestamp"));
        KeyValueSinkFactory sinkFactory = KeyValueSinkFactory.getInstance(SequenceFileSink.class, sinkConfig);
        sh.addLast(sinkFactory);

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

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

        prepareHealthChecks();

        // Begin polling
        consumer.poll();
    } catch (ParseException e) {
        LOG.error("Error parsing command line options", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(KafkaSequenceFileConsumer.class.getName(), options);
    } catch (NumberFormatException e) {
        LOG.error("Failed to parse filesize option", e);
    }
}

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

/**
 * Entry point for Scale command./*from w ww.  j  a v a  2s  .  c om*/
 * @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");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option alternateOption = OptionBuilder.withArgName("alternate").hasArg().withType(new String())
            .withDescription("The new alternate to switch to.").create("alternate");

    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(alternateOption);

    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");
    String pellet = line.getOptionValue("pellet");
    String alternate = line.getOptionValue("alternate");

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

    try {

        FloeClient.getInstance().getClient().switchAlternate(app, pellet, alternate);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:com.linkedin.restli.tools.snapshot.gen.RestLiSnapshotExporterCmdLineApp.java

/**
 * @param args restliexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir]
 *///from w  w w. ja v a2s. co  m
public static void main(String[] args) {
    CommandLine cl = null;
    try {
        final CommandLineParser parser = new GnuParser();
        cl = parser.parse(OPTIONS, args);
    } catch (ParseException e) {
        System.err.println("Invalid arguments: " + e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "restliexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]"
                        + "[-name api_name] [-outdir outdir]",
                OPTIONS);
        System.exit(0);
    }

    final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);

    try {
        final RestLiSnapshotExporter exporter = new RestLiSnapshotExporter();
        exporter.setResolverPath(resolverPath);
        exporter.export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"),
                cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceClasses"),
                cl.getOptionValue("outdir", "."),
                AdditionalDocProvidersUtil.findDocProviders(log, cl.hasOption("loadAdditionalDocProviders")));
    } catch (Throwable e) {
        log.error("Error writing Snapshot files", e);
        System.out.println("Error writing Snapshot files:\n" + e);
        System.exit(1);
    }
}

From source file:de.akadvh.view.Main.java

/**
 * @param args// ww  w.  j  a v  a 2  s .  co  m
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("u", "user", true, "Benutzername");
    options.addOption("p", "pass", true, "Passwort");
    options.addOption("c", "console", false, "Consolenmodus");
    options.addOption("v", "verbose", false, "Mehr Ausgabe");
    options.addOption("m", "modul", true, "Modul");
    options.addOption("n", "noten", false, "Notenuebersicht erstellen");
    options.addOption("t", "termin", false, "Terminuebersicht (angemeldete Module) downloaden");
    options.addOption("version", false, "Version");
    options.addOption("h", "help", false, "Hilfe");

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar akadvh.jar", options);
            System.exit(0);
        }

        if (cmd.hasOption("version")) {

            System.out.println("Akadvh Version: " + Akadvh.getVersion());
            System.exit(0);

        }

        if (cmd.hasOption("console")) {

            ConsoleView cv = new ConsoleView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"),
                    cmd.getOptionValue("modul"), cmd.hasOption("noten"), cmd.hasOption("termin"),
                    cmd.hasOption("verbose"));

        } else {

            SwingView sv = new SwingView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"));

        }

    } catch (UnrecognizedOptionException e1) {
        System.out.println(e1.getMessage());
        System.out.println("--help fuer Hilfe");
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:edu.washington.data.sentimentreebank.StanfordNLPDict.java

public static void main(String args[]) {
    Options options = new Options();
    options.addOption("d", "dict", true, "dictionary file.");
    options.addOption("s", "sentiment", true, "sentiment value file.");

    CommandLineParser parser = new GnuParser();
    try {/*  ww  w . j  av a  2  s. com*/
        CommandLine line = parser.parse(options, args);
        if (!line.hasOption("dict") && !line.hasOption("sentiment")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("StanfordNLPDict", options);
            return;
        }

        Path dictPath = Paths.get(line.getOptionValue("dict"));
        Path sentimentPath = Paths.get(line.getOptionValue("sentiment"));

        StanfordNLPDict snlp = new StanfordNLPDict(dictPath, sentimentPath);
        String sentence = "take off";
        System.out.printf("sentence [%1$s] %2$s\n", sentence,
                String.valueOf(snlp.getPhraseSentiment(sentence)));

    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("StanfordNLPDict", options);
    } catch (IOException ex) {
        Logger.getLogger(StanfordNLPDict.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:is.iclt.icenlp.runner.RunLemmald.java

public static void main(String[] args) {

    CommandLineParser parser = new GnuParser();
    try {// w w  w  .j a  v a  2 s  .  c o  m
        // parse the command line arguments
        CommandLine cmdLine = parser.parse(options, args);
        if (cmdLine.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("lemmatize.sh", options);
        } else {
            runConsole(cmdLine);
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Could not parse command line arguments.  Reason: " + exp.getMessage());
    }

}

From source file:it.crs4.features.ImageToAvro.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    CommandLine cmd = null;//w  ww .  ja  va  2  s.  c  o m
    try {
        cmd = parseCmdLine(opts, args);
    } catch (ParseException e) {
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
    }
    String fn = null;
    try {
        fn = cmd.getArgs()[0];
    } catch (ArrayIndexOutOfBoundsException e) {
        HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp("java ImageToAvro IMG_FILE", opts);
        System.exit(2);
    }
    String outDirName = null;
    if (cmd.hasOption("outdir")) {
        outDirName = cmd.getOptionValue("outdir");
        File outDir = new File(outDirName);
        if (!outDir.exists()) {
            boolean ret = outDir.mkdirs();
            if (!ret) {
                System.err.format("ERROR: can't create %s\n", outDirName);
                System.exit(3);
            }
        }
    }

    String name = PathTools.stripext(PathTools.basename(fn));
    ImageReader reader = new ImageReader();
    reader.setId(fn);
    LOGGER.info("Reading from {}", fn);
    BioImgFactory factory = new BioImgFactory(reader);
    int seriesCount = factory.getSeriesCount();

    // FIXME: add support for XY slicing
    String seriesName;
    String outFn;
    for (int i = 0; i < seriesCount; i++) {
        seriesName = String.format("%s_%d", name, i);
        outFn = new File(outDirName, seriesName + ".avro").getPath();
        factory.setSeries(i);
        factory.writeSeries(seriesName, outFn);
        LOGGER.info("Writing to {}", outFn);
    }
    reader.close();
    LOGGER.info("All done");
}

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

public static void main(String[] args) {
    OptionFactory optFactory = OptionFactory.getInstance();
    Options options = KafkaConsumer.getOptions();
    options.addOption(optFactory.create("tbl", "table", true, "HBase table name.").required());
    options.addOption(optFactory.create("f", "family", true, "Column family."));
    options.addOption(optFactory.create("q", "qualifier", true, "Column qualifier."));
    options.addOption(/*  w ww  . java2s .c om*/
            optFactory.create("b", "batchsize", true, "Batch size (number of messages per HBase flush)."));
    options.addOption(optFactory.create("pd", "prefixdate", false, "Prefix key with salted date."));

    CommandLineParser parser = new GnuParser();
    ShutdownHook sh = ShutdownHook.getInstance();
    try {
        // 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();
        if (cmd.hasOption("numthreads")) {
            sinkConfig.setInt("hbasesink.hbase.numthreads", Integer.parseInt(cmd.getOptionValue("numthreads")));
        }
        if (cmd.hasOption("batchsize")) {
            sinkConfig.setInt("hbasesink.hbase.batchsize", Integer.parseInt(cmd.getOptionValue("batchsize")));
        }
        sinkConfig.setString("hbasesink.hbase.tablename", cmd.getOptionValue("table"));
        sinkConfig.setString("hbasesink.hbase.column.family", cmd.getOptionValue("family", "data"));
        sinkConfig.setString("hbasesink.hbase.column.qualifier", cmd.getOptionValue("qualifier", "json"));
        sinkConfig.setBoolean("hbasesink.hbase.rowkey.prefixdate", cmd.hasOption("prefixdate"));
        KeyValueSinkFactory sinkFactory = KeyValueSinkFactory.getInstance(HBaseSink.class, sinkConfig);
        sh.addLast(sinkFactory);

        // Set the sink factory 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:cz.deco.Main.java

public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    DecoContextImpl context = new DecoContextImpl();
    Options options = getOptions();/*w w w.jav  a  2s  .  c om*/
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar deco.jar", options);
        return;
    }

    String source = cmd.getOptionValue("s");
    String target = cmd.getOptionValue("t");
    String plan = cmd.getOptionValue("p");
    String temp = cmd.getOptionValue("d");

    context.setOutputArchive(new File(target).getAbsoluteFile().toPath());
    context.setApplicationArchive(new File(source).getAbsoluteFile().toPath());
    Path temporaryDir;
    if (cmd.hasOption("d")) {
        temporaryDir = new File(temp).getAbsoluteFile().toPath();
    } else {
        temporaryDir = getTempDirectory();
    }
    context.setTemporaryDir(temporaryDir);
    context.setDeploymentPlan(new File(plan).getAbsoluteFile().toPath());

    new Application().doWork(context);

    cleanUp(temporaryDir);

}