Java 类org.apache.commons.cli.HelpFormatter 实例源码

项目:pm-home-station    文件:Start.java   
public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    try {
        Options options = getOptions();
        CommandLine line = parser.parse(options, args );
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            System.out.println(Constants.PROJECT_NAME + ", " + Constants.PROJECT_URL);
            formatter.printHelp(Constants.PROJECT_NAME, options, true);
        } else if (line.hasOption("version")) {
            System.out.println("version: " + Constants.VERSION);
        } else {
            logger.info("Starting pm-home-station ({} v.{})...", Constants.PROJECT_URL, Constants.VERSION);
            setLookAndFeel();
            PlanTowerSensor planTowerSensor = new PlanTowerSensor();
            Station station = new Station(planTowerSensor);
            SwingUtilities.invokeLater(() -> { station.showUI(); });
        }
    } catch (ParseException e) {
        logger.error("Ooops", e);
        return;
    }
}
项目:LibScout    文件:TplCLI.java   
private static void usage() {
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    String helpMsg = USAGE;

    if (OpMode.PROFILE.equals(CliOptions.opmode))
        helpMsg = USAGE_PROFILE;
    else if (OpMode.MATCH.equals(CliOptions.opmode))
        helpMsg = USAGE_MATCH;
    else if (OpMode.DB.equals(CliOptions.opmode))
        helpMsg = USAGE_DB;
    else if (OpMode.LIB_API_ANALYSIS.equals(CliOptions.opmode))
        helpMsg = USAGE_LIB_API_ANALYSIS;

    formatter.printHelp(helpMsg, options);
    System.exit(1);
}
项目:AthenaX    文件:AthenaXServer.java   
public static void main(String[] args) throws Exception {
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(CLI_OPTIONS, args);
  if (!line.hasOption("conf")) {
    System.err.println("No configuration file is specified");
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("athenax-server", CLI_OPTIONS);
    System.exit(1);
  }

  try {
    String confFile = line.getOptionValue("conf");
    AthenaXConfiguration conf = AthenaXConfiguration.load(Paths.get(confFile).toFile());
    new AthenaXServer().start(conf);
  } catch (IOException | ClassNotFoundException e) {
    System.err.println("Failed to parse configuration.");
    throw e;
  }
}
项目:rocketmq-rocketmq-all-4.1.0-incubating    文件:ServerUtil.java   
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
项目:aceql-http    文件:WebServer.java   
/**
 * Prints usage
 * 
 * @param options
 *            the CLI Options
 */
private static void printUsage(Options options) {
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(400);

    String fromAceqlServerScript = System.getProperty("from.aceql-server.script");

    String help = null;

    if (fromAceqlServerScript != null && fromAceqlServerScript.equals("true")) {
        help = "aceql-server -start -host <hostname> -port <port> -properties <file>" + CR_LF + "or " + CR_LF
                + "-stop -port <port> ";
    } else {
        help = "java org.kawanfw.sql.WebServer -start -host <hostname> -port <port> -properties <file>" + CR_LF
                + "or " + CR_LF + "-stop -port <port> ";
    }

    formatter.printHelp(help, options);
    System.out.println();
}
项目:devops-cm-client    文件:Commands.java   
private static void printHelp() throws Exception {

        String cmd = "<CMD>";
        String CRLF = "\r\n";
        StringWriter subCommandsHelp = new StringWriter();

            commands.stream().map(it -> it.getAnnotation(CommandDescriptor.class).name())
            .sorted().forEach(subcmd ->
            subCommandsHelp.append(StringUtils.repeat(' ', 4))
                           .append(subcmd)
                           .append(CRLF)
        );

        String cmdLineSyntax = format("%s [COMMON_OPTIONS...] <subcommand> [SUBCOMMAND_OPTIONS] <parameters...>", cmd);
        String header = "Manages communication with the SAP CM System.\r\nCOMMON OPTIONS:";
        String footer = format("Subcommands:%s%s%sType '%s <subcommand> --help' for more details.%s",
            CRLF, subCommandsHelp.toString(), CRLF, cmd, CRLF);

        new HelpFormatter().printHelp(
            cmdLineSyntax, header,
            Helpers.getStandardOptions(),
            footer);
    }
项目:sbc-qsystem    文件:QConfig.java   
/**
 * @param args cmd params
 */
public QConfig prepareCLI(String[] args) {
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        throw new RuntimeException("Parsing failed.  Reason: ", exp);
    }

    new HelpFormatter().printHelp("command line parameters for QMS QSystem...", options);
    // automatically generate the help statement
    if (line.hasOption("help") || line.hasOption("h") || line.hasOption("?")) {

        System.exit(0);
    }

    QLog.l().logger().info("Properties are ready.");
    return this;
}
项目:pravega-samples    文件:ConsoleReader.java   
public static void main(String[] args) {
    Options options = getOptions();
    CommandLine cmd = null;
    try {
        cmd = parseCommandLineArgs(options, args);
    } catch (ParseException e) {
        System.out.format("%s.%n", e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ConsoleReader", options);
        System.exit(1);
    }

    final String scope = cmd.getOptionValue("scope") == null ? Constants.DEFAULT_SCOPE : cmd.getOptionValue("scope");
    final String streamName = cmd.getOptionValue("name") == null ? Constants.DEFAULT_STREAM_NAME : cmd.getOptionValue("name");
    final String uriString = cmd.getOptionValue("uri") == null ? Constants.DEFAULT_CONTROLLER_URI : cmd.getOptionValue("uri");
    final URI controllerURI = URI.create(uriString);

    ConsoleReader reader = new ConsoleReader(scope, streamName, controllerURI);
    reader.run();
}
项目:amqp-kafka-demo    文件:Server.java   
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("q", true, "Queue");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {

      CommandLine cmd = parser.parse(options, args);

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

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Sender", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String address = cmd.getOptionValue("q", QUEUE);

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
        props.put("queue.myDestinationLookup", address);

        LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort);

        Server sender = new Server();
        sender.run(props);
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
项目:hadoop    文件:HamletGen.java   
public static void main(String[] args) throws Exception {
  CommandLine cmd = new GnuParser().parse(opts, args);
  if (cmd.hasOption("help")) {
    new HelpFormatter().printHelp("Usage: hbgen [OPTIONS]", opts);
    return;
  }
  // defaults
  Class<?> specClass = HamletSpec.class;
  Class<?> implClass = HamletImpl.class;
  String outputClass = "HamletTmp";
  String outputPackage = implClass.getPackage().getName();
  if (cmd.hasOption("spec-class")) {
    specClass = Class.forName(cmd.getOptionValue("spec-class"));
  }
  if (cmd.hasOption("impl-class")) {
    implClass = Class.forName(cmd.getOptionValue("impl-class"));
  }
  if (cmd.hasOption("output-class")) {
    outputClass = cmd.getOptionValue("output-class");
  }
  if (cmd.hasOption("output-package")) {
    outputPackage = cmd.getOptionValue("output-package");
  }
  new HamletGen().generate(specClass, implClass, outputClass, outputPackage);
}
项目:rmq4note    文件:ServerUtil.java   
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
项目:FreeCol    文件:FreeCol.java   
/**
 * Prints the usage message and exits.
 *
 * @param options The command line {@code Options}.
 * @param status The status to exit with.
 */
private static void printUsage(Options options, int status) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("java -Xmx 256M -jar freecol.jar [OPTIONS]",
                        options);
    System.exit(status);
}
项目:BiglyBT    文件:OptionsConsoleCommand.java   
@Override
    public void printHelpExtra(PrintStream out, List args)
    {
        HelpFormatter formatter = new HelpFormatter();
        PrintWriter writer = new PrintWriter(out);
        writer.println("> -----");
        writer.println(getCommandDescriptions());
//      formatter.printHelp(writer, 80, getCommandDescriptions(), ">>>", getOptions(), 4, 4, ">>>", true);
        formatter.printOptions(writer, 80, getOptions(), 4, 4);
        writer.println("> -----");
        writer.flush();
    }
项目:bireme    文件:Bireme.java   
protected void parseCommandLine(String[] args)
    throws DaemonInitException, ConfigurationException, BiremeException {
  Option help = new Option("help", "print this message");
  Option configFile =
      Option.builder("config_file").hasArg().argName("file").desc("config file location").build();

  Options opts = new Options();
  opts.addOption(help);
  opts.addOption(configFile);
  CommandLine cmd = null;
  CommandLineParser parser = new DefaultParser();

  try {
    cmd = parser.parse(opts, args);

    if (cmd.hasOption("help")) {
      throw new ParseException("print help message");
    }
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    formatter.printHelp(writer, formatter.getWidth(), "Bireme", null, opts,
        formatter.getLeftPadding(), formatter.getDescPadding(), null, true);
    writer.flush();
    String result = out.toString();
    throw new DaemonInitException(result);
  }

  String config = cmd.getOptionValue("config_file", DEFAULT_CONFIG_FILE);

  cxt = new Context(new Config(config));
}
项目:flink-charts    文件:BatchMain.java   
/**
 *  Flink-charts batch job. Giving the parameters:
 *
 *  chart 3
 *
 *  Should output the top 3 most tagged tracks irrespective of user location. The output should
 *  be in a columnar format and contain the following fields:
 *  CHART POSITION , TRACK TITLE , ARTIST NAME
 *
 *  Thus, the output may be as follows:
 *      1 Shape Of You Ed Sheeran
 *      2 24k Magic Bruno Mars
 *      3 This Girl Kungs
 *
 *  Similarly, giving the parameters:
 *
 *  state_chart 3
 *
 *  Should output the top 3 tracks in each and every US state. The output format for the state
 *  chart should be similar to the above, but you are free to define it.
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

    ArgsParser argsParser= null;

    try {
        log.debug("Parsing input parameters ");
        argsParser= ArgsParser.builder(args);

    } catch (ParseException ex) {
        log.error("Unable to parse arguments");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(CLI_CMD, ArgsParser.getDefaultOptions());
        System.exit(1);
    }

    log.debug("Initializing job: " + argsParser.toString());
    PipelineChartsConf pipelineConf= new PipelineChartsConf(argsParser);

    if (argsParser.getChartType().equals(ArgsParser.chartTypeOptions.chart.toString())) {
        log.debug("Starting Simple Charts job. Getting top track chart!");
        SimpleChartsPipeline.run(pipelineConf);

    } else if (argsParser.getChartType().equals(ArgsParser.chartTypeOptions.state_chart.toString())) {
        log.debug("Starting State Charts job. Getting top track charts by State (country: " +
                argsParser.getConfig().getString("ingestion.stateChart.country")+ ").");
        StateChartsPipeline.run(pipelineConf);

    } else  {
        log.error("Unable to parse arguments");
        System.exit(1);
    }


}
项目:stl-decomp-4j    文件:StlPerfTest.java   
private static void parseCommandLine(String[] args) {
    Options options = new Options();

    Option input = new Option("n", "timed-iterations", true, "number of iterations of timing loop");
    input.setRequired(false);
    options.addOption(input);

    Option output = new Option("w", "warmup-iterations", true, "number of warm-up iterations before timing loop");
    output.setRequired(false);
    options.addOption(output);

    Option hourly = new Option("h", "hourly", false, "whether to use hourly data");
    hourly.setRequired(false);
    options.addOption(hourly);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("StlPerfTest", options);

        System.exit(1);
        return;
    }

    if (cmd.hasOption("hourly")) {
        System.out.println("Running hourly stress test");
        fRunCo2 = false;
        fTimedIterations = 200;
        fWarmupIterations = 30;
    } else {
        System.out.println("Running CO2 test");
        fTimedIterations = 2000;
        fWarmupIterations = 30;
    }

    String nStr = cmd.getOptionValue("number");
    if (nStr != null)
        fTimedIterations = Integer.parseInt(nStr);

    String wStr = cmd.getOptionValue("warmup-iterations");
    if (wStr != null)
        fWarmupIterations = Integer.parseInt(wStr);

}
项目:hbs_decipher    文件:QNAPFileDecrypter.java   
/**
 * Write "help" to the provided OutputStream.
 */
private static void printHelp(final Options options, final int printedRowWidth, final String header,
        final String footer, final int spacesBeforeOption, final int spacesBeforeOptionDescription,
        final boolean displayUsage, final OutputStream out) {
    final String commandLineSyntax = "java -jar qnap_decrypt_XXX.jar";
    final PrintWriter writer = new PrintWriter(out);
    final HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.printHelp(writer, printedRowWidth, commandLineSyntax, header, options, spacesBeforeOption,
            spacesBeforeOptionDescription, footer, displayUsage);
    writer.close();
}
项目:devops-cm-client    文件:Commands.java   
static void handleHelpOption(String usage, String header, Options options) {

            String footer = "Exit codes:\n"
                    + "    0  The request completed successfully.\n"
                    + "    1  The request did  not complete successfully and\n"
                    + "       no more specific return code as defined below applies.\n"
                    + "    2  Wrong credentials.";
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("<CMD> [COMMON_OPTIONS] "+ usage, header, options, footer);
        }
项目:ditb    文件:HFileV1Detector.java   
private boolean parseOption(String[] args) throws ParseException, IOException {
  if (args.length == 0) {
    return true; // no args will process with default values.
  }
  CommandLineParser parser = new GnuParser();
  CommandLine cmd = parser.parse(options, args);
  if (cmd.hasOption("h")) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("HFileV1Detector", options, true);
    System.out
        .println("In case no option is provided, it processes hbase.rootdir using 10 threads.");
    System.out.println("Example:");
    System.out.println(" To detect any HFileV1 in a given hbase installation '/myhbase':");
    System.out.println(" $ $HBASE_HOME/bin/hbase " + this.getClass().getName() + " -p /myhbase");
    System.out.println();
    return false;
  }

  if (cmd.hasOption("p")) {
    this.targetDirPath = new Path(FSUtils.getRootDir(getConf()), cmd.getOptionValue("p"));
  }
  try {
    if (cmd.hasOption("n")) {
      int n = Integer.parseInt(cmd.getOptionValue("n"));
      if (n < 0 || n > 100) {
        LOG.warn("Please use a positive number <= 100 for number of threads."
            + " Continuing with default value " + DEFAULT_NUM_OF_THREADS);
        return true;
      }
      this.numOfThreads = n;
    }
  } catch (NumberFormatException nfe) {
    LOG.error("Please select a valid number for threads");
    return false;
  }
  return true;
}
项目:WebPLP    文件:AssembleConsole.java   
private static void printHelp()
{
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("Assembler Console",
            "Your one stop shop, when you are lost and don't know what to do!",
            options, "Thank you for using Assembler Console!");
    System.exit(0);
}
项目:ditb    文件:RESTServer.java   
private static void printUsageAndExit(Options options, int exitCode) {
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("bin/hbase rest start", "", options,
    "\nTo run the REST server as a daemon, execute " +
    "bin/hbase-daemon.sh start|stop rest [--infoport <port>] [-p <port>] [-ro]\n", true);
  System.exit(exitCode);
}
项目:cyberduck    文件:TerminalHelpPrinterTest.java   
@Test
@Ignore
public void testPrintWidth20DefaultFormatter() throws Exception {
    final HelpFormatter f = new HelpFormatter();
    f.setWidth(20);
    TerminalHelpPrinter.print(TerminalOptionsBuilder.options(), f);
}
项目:sponge    文件:StandaloneEngineBuilder.java   
public void printHelp() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("Usage: ");
    formatter.setOptionComparator(null);

    String columns = System.getenv(ENV_COLUMNS);
    if (columns != null) {
        try {
            formatter.setWidth(Integer.parseInt(columns));
        } catch (Exception e) {
            logger.warn(e.toString());
        }
    }

    String header = "Run the " + VersionInfo.PRODUCT + " standalone command-line application.\n\n";
    String leftPadding = StringUtils.repeat(' ', formatter.getLeftPadding());
    //@formatter:off
    String footer = new StringBuilder()
            .append("\nExamples (change directory to " + VersionInfo.PRODUCT + " bin/ first):\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -c ../examples/script/py/hello_world.xml\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -k helloWorldKb=../examples/script/py/hello_world.py\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -k ../examples/script/py/hello_world.py\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME
                    + " -k filtersKb=../examples/script/py/filters.py -k heartbeatKb=../examples/script/js/rules_heartbeat.js\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME
                    + " -k ../examples/standalone/multiple_kb_files/event_processors.py"
                    + ",../examples/standalone/multiple_kb_files/example2.py\n")
            .append("\nPress CTRL+C to exit the " + VersionInfo.PRODUCT + " standalone command-line application.\n")
            .append("\nSee http://sponge.openksavi.org for more details.").toString();
    //@formatter:on
    formatter.printHelp(EXECUTABLE_NAME, header, options, footer, true);
}
项目:BNPMix.java    文件:OptionPacks.java   
public void printHelp(String header) {
  HelpFormatter formatter = new HelpFormatter();
  System.out.println(header);
  System.out.println();
  formatter.setSyntaxPrefix("Option pack ");
  for ( OptionPack pack : this ) {
    formatter.printHelp( pack.getClass().getSimpleName(), pack );
  }
}
项目:java-cli-demos    文件:MainWithBuilder.java   
/**
 * Generate usage information with Apache Commons CLI.
 *
 * @param options Instance of Options to be used to prepare
 *    usage formatter.
 * @return HelpFormatter instance that can be used to print
 *    usage information.
 */
private static void printUsage(final Options options)
{
   final HelpFormatter formatter = new HelpFormatter();
   final String syntax = "Main";
   out.println("\n=====");
   out.println("USAGE");
   out.println("=====");
   final PrintWriter pw  = new PrintWriter(out);
   formatter.printUsage(pw, 80, syntax, options);
   pw.flush();
}
项目:freecol    文件:FreeCol.java   
/**
 * Prints the usage message and exits.
 *
 * @param options The command line {@code Options}.
 * @param status The status to exit with.
 */
private static void printUsage(Options options, int status) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("java -Xmx 256M -jar freecol.jar [OPTIONS]",
                        options);
    System.exit(status);
}
项目:appdomain    文件:MainApp.java   
/**
 * 
 * @param options
 * @param message
 */
protected static void printHelp(Options options,String message) {
    if (message!=null) System.out.println(message);
    System.out.println(title);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp( MainApp.class.getName(), options );
    System.out.println("Examples:");
    System.out.println(example_demo_fp());
    System.out.println(example_demo_density());
    System.out.println(example_density());


    Runtime.getRuntime().runFinalization();                      
    Runtime.getRuntime().exit(0);   
}
项目:api-harvester    文件:Main.java   
public static void main(String[] args)
    throws IOException, URISyntaxException, TransformerException, ParserConfigurationException, SAXException, ParseException {

  Options options = new Options();
  options.addOption("h", "help", false, "help output");
  options.addOption("c", "convert", false, "enable only convertion of input");
  options.addOption("d", "outputDirectoryPath", true, "output directory path");
  options.addOption("o", "outputFileName", true, "output filename");
  options.addOption("l", "listElementNames", true, "if json is list, set the element names");
  options.addOption("r", "rootElementName", true, "root element name");
  options.addOption("f", "filePath", true, "file to read from");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  if (cmd.hasOption("h") || cmd.hasOption("help")) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("xml converter", options);
    return;
  }

  if (cmd.hasOption("c") || cmd.hasOption("convert")) {
    LOGGER.info("Json convert enabled");
    jsonConvert(cmd);
    LOGGER.info("Json conversion finished");
  } else {
    LOGGER.info("Harvesting enabled");
    apiHarverst();
    LOGGER.info("Harvest finished");
  }
}
项目:aliyun-maxcompute-data-collectors    文件:ToolOptions.java   
/**
 * Print the help to the specified PrintWriter, using the specified
 * help formatter.
 * @param formatter the HelpFormatter to use.
 * @param pw the PrintWriter to emit to.
 */
public void printHelp(HelpFormatter formatter, PrintWriter pw) {
  boolean first = true;
  for (RelatedOptions optGroup : optGroups) {
    if (!first) {
      pw.println("");
    }
    pw.println(optGroup.getTitle() + ":");
    formatter.printOptions(pw, formatter.getWidth(), optGroup, 0, 4);
    first = false;
  }
}
项目:samza-sql-tools    文件:GenerateKafkaEvents.java   
public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException {
  _randValueGenerator = new RandomValueGenerator(System.currentTimeMillis());
  Options options = new Options();
  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_TOPIC_NAME, OPT_LONG_TOPIC_NAME, OPT_ARG_TOPIC_NAME, true, OPT_DESC_TOPIC_NAME));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_BROKER, OPT_LONG_BROKER, OPT_ARG_BROKER, false, OPT_DESC_BROKER));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_NUM_EVENTS, OPT_LONG_NUM_EVENTS, OPT_ARG_NUM_EVENTS, false, OPT_DESC_NUM_EVENTS));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_EVENT_TYPE, OPT_LONG_EVENT_TYPE, OPT_ARG_EVENT_TYPE, false, OPT_DESC_EVENT_TYPE));

  CommandLineParser parser = new BasicParser();
  CommandLine cmd;
  try {
    cmd = parser.parse(options, args);
  } catch (Exception e) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(String.format("Error: %s%ngenerate-events.sh", e.getMessage()), options);
    return;
  }

  String topicName = cmd.getOptionValue(OPT_SHORT_TOPIC_NAME);
  String broker = cmd.getOptionValue(OPT_SHORT_BROKER, DEFAULT_BROKER);
  long numEvents = Long.parseLong(cmd.getOptionValue(OPT_SHORT_NUM_EVENTS, String.valueOf(Long.MAX_VALUE)));
  String eventType = cmd.getOptionValue(OPT_SHORT_EVENT_TYPE);
  generateEvents(broker, topicName, eventType, numEvents);
}
项目:amqp-kafka-demo    文件:Client.java   
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("q", true, "Queue");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {

      CommandLine cmd = parser.parse(options, args);

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

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Sender", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String address = cmd.getOptionValue("q", QUEUE);

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
        props.put("queue.myDestinationLookup", address);

        LOG.info("Starting client : connecting to [{}:{}]", messagingHost, messagingPort);

        Client sender = new Client();
        sender.run(props);
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
项目:Cognizant-Intelligent-Test-Scripter    文件:CLI.java   
static void help() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setDescPadding(0);
    formatter.setOptionComparator(null);
    System.out.println("CLI\n"
            + "Invoke command line options  for retrieving execution details, setting variable, change settings etc.");
    formatter.printHelp("\nRun.bat", LookUp.OPTIONS, true);
}
项目:ditb    文件:ThriftServer.java   
private static void printUsageAndExit(Options options, int exitCode)
    throws ExitCodeException {
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("Thrift", null, options,
      "To start the Thrift server run 'bin/hbase-daemon.sh start thrift'\n" +
      "To shutdown the thrift server run 'bin/hbase-daemon.sh stop " +
      "thrift' or send a kill signal to the thrift server pid",
      true);
  throw new ExitCodeException(exitCode, "");
}
项目:hadoop    文件:LogsCLI.java   
private void printHelpMessage(Options options) {
  System.out.println("Retrieve logs for completed YARN applications.");
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("yarn logs -applicationId <application ID> [OPTIONS]", new Options());
  formatter.setSyntaxPrefix("");
  formatter.printHelp("general options are:", options);
}
项目:samza-sql-tools    文件:EventHubConsoleConsumer.java   
public static void main(String[] args)
    throws ServiceBusException, IOException, ExecutionException, InterruptedException {
  Options options = new Options();
  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_EVENTHUB_NAME, OPT_LONG_EVENTHUB_NAME, OPT_ARG_EVENTHUB_NAME, true,
      OPT_DESC_EVENTHUB_NAME));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_NAMESPACE, OPT_LONG_NAMESPACE, OPT_ARG_NAMESPACE, true, OPT_DESC_NAMESPACE));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_KEY_NAME, OPT_LONG_KEY_NAME, OPT_ARG_KEY_NAME, true, OPT_DESC_KEY_NAME));

  options.addOption(
      CommandLineHelper.createOption(OPT_SHORT_TOKEN, OPT_LONG_TOKEN, OPT_ARG_TOKEN, true, OPT_DESC_TOKEN));

  CommandLineParser parser = new BasicParser();
  CommandLine cmd;
  try {
    cmd = parser.parse(options, args);
  } catch (Exception e) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(String.format("Error: %s%neh-console-consumer.sh", e.getMessage()), options);
    return;
  }

  String ehName = cmd.getOptionValue(OPT_SHORT_EVENTHUB_NAME);
  String namespace = cmd.getOptionValue(OPT_SHORT_NAMESPACE);
  String keyName = cmd.getOptionValue(OPT_SHORT_KEY_NAME);
  String token = cmd.getOptionValue(OPT_SHORT_TOKEN);

  consumeEvents(ehName, namespace, keyName, token);
}
项目:hadoop    文件:SecondaryNameNode.java   
void usage() {
  String header = "The Secondary NameNode is a helper "
      + "to the primary NameNode. The Secondary is responsible "
      + "for supporting periodic checkpoints of the HDFS metadata. "
      + "The current design allows only one Secondary NameNode "
      + "per HDFS cluster.";
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("secondarynamenode", header, options, "", false);
}
项目:FuzzDroid    文件:FrameworkOptions.java   
private void showHelpMessage() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp( "Android Environment Constraint Generator", options );
}
项目:WarcExtractor    文件:CommandLineParser.java   
private static void printUsage(Options options) {
    new HelpFormatter().printHelp("Warc Extractor", options, true);
    System.exit(0);
}
项目:nn_nex_logging_and_research    文件:StarterFunctionFinder.java   
private static void showHelp(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(100);
    formatter.printHelp(" ", options);
}