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

下面列出了怎么用org.apache.commons.cli.HelpFormatter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: DDMQ   文件: 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;
}
 
源代码2 项目: quaerite   文件: WinnowAnalyzedElevate.java
public static void main(String[] args) throws Exception {
    CommandLine commandLine = null;

    try {
        commandLine = new DefaultParser().parse(OPTIONS, args);
    } catch (ParseException e) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(
                "java -jar org.mitre.quaerite.solrtools.WinnowAnalyzedElevate",
                OPTIONS);
        return;
    }
    Path inputElevate = Paths.get(commandLine.getOptionValue("e"));
    Path winnowElevate = Paths.get(commandLine.getOptionValue("w"));

    SearchClient client = SearchClientFactory.getClient(commandLine.getOptionValue("s"));
    String analysisField = commandLine.getOptionValue("f");
    DocSorter docSorter = new DocSorter(commandLine.getOptionValue("i"));
    boolean commentWinnowed = (commandLine.hasOption("c") ? true : false);
    WinnowAnalyzedElevate winnowAnalyzedElevate = new WinnowAnalyzedElevate(docSorter, commentWinnowed);
    winnowAnalyzedElevate.execute(inputElevate, winnowElevate, client, analysisField);
}
 
源代码3 项目: hmftools   文件: CreateShallowSeqDB.java
public static void main(@NotNull String[] args) throws ParseException, IOException {
    Options options = createBasicOptions();
    CommandLine cmd = createCommandLine(args, options);

    if (!checkInputs(cmd)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("shallow seq db ", options);
        System.exit(1);
    }

    LOGGER.info("Loading shallow seq runs from {}", cmd.getOptionValue(RUNS_DIRECTORY));
    List<RunContext> runContexts = loadRunContexts(cmd.getOptionValue(RUNS_DIRECTORY));

    List<LimsShallowSeqData> newShallowSeqEntries = extractNewEntriesForShallowDbFromRunContexts(runContexts,
            cmd.getOptionValue(SHALLOW_SEQ_TSV),
            cmd.getOptionValue(RUNS_DIRECTORY),
            cmd.getOptionValue(PURPLE_QC_FILE),
            cmd.getOptionValue(PURPLE_PURITY_P4_TSV),
            cmd.getOptionValue(PURPLE_PURITY_P5_TSV),
            cmd.getOptionValue(PIPELINE_VERSION));

    appendToCsv(cmd.getOptionValue(SHALLOW_SEQ_TSV), newShallowSeqEntries);

    LOGGER.info("Shallow seq DB is complete!");
}
 
源代码4 项目: Flink-CEPplus   文件: FlinkYarnSessionCli.java
private void printUsage() {
	System.out.println("Usage:");
	HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(200);
	formatter.setLeftPadding(5);
	formatter.setSyntaxPrefix("   Required");
	Options req = new Options();
	req.addOption(container);
	formatter.printHelp(" ", req);

	formatter.setSyntaxPrefix("   Optional");
	Options options = new Options();
	addGeneralOptions(options);
	addRunOptions(options);
	formatter.printHelp(" ", options);
}
 
源代码5 项目: hmftools   文件: HealthChecksApplication.java
public static void main(final String... args) throws ParseException, IOException {
    Options options = createOptions();
    CommandLine cmd = createCommandLine(options, args);

    String refSample = cmd.getOptionValue(REF_SAMPLE);
    String metricsDir = cmd.getOptionValue(METRICS_DIR);
    String outputDir = cmd.getOptionValue(OUTPUT_DIR);

    if (refSample == null || metricsDir == null || outputDir == null) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Health-Checks", options);
        System.exit(1);
    }

    String tumorSample = cmd.hasOption(TUMOR_SAMPLE) ? cmd.getOptionValue(TUMOR_SAMPLE) : null;
    String amberDir = cmd.hasOption(AMBER_DIR) ? cmd.getOptionValue(AMBER_DIR) : null;
    String purpleDir = cmd.hasOption(PURPLE_DIR) ? cmd.getOptionValue(PURPLE_DIR) : null;

    new HealthChecksApplication(refSample, tumorSample, metricsDir, amberDir, purpleDir, outputDir).run(true);
}
 
源代码6 项目: hmftools   文件: PonApplication.java
public static void main(String[] args) throws IOException, ParseException, ExecutionException, InterruptedException {
    final Options options = createOptions();
    final CommandLine cmd = createCommandLine(args, options);
    final String inputFilePath = cmd.getOptionValue(IN_VCF);
    final String outputFilePath = cmd.getOptionValue(OUT_VCF);
    final int threads = Configs.defaultIntValue(cmd, THREADS, 5);

    if (outputFilePath == null || inputFilePath == null) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("PonApplication", options);
        System.exit(1);
    }

    try (PonApplication app = new PonApplication(threads, inputFilePath, outputFilePath)) {
        app.run();
    }
}
 
源代码7 项目: parquet-tools   文件: Main.java
public static void showUsage(HelpFormatter format, PrintWriter err, String name, Command command) {
  Options options = mergeOptions(OPTIONS, command.getOptions());
  String[] usage = command.getUsageDescription();

  String ustr = name + " [option...]";
  if (usage != null && usage.length >= 1) {
    ustr = ustr + " " + usage[0];
  }
    
  format.printUsage(err, WIDTH, ustr);
  format.printWrapped(err, WIDTH, LEFT_PAD, "where option is one of:");
  format.printOptions(err, WIDTH, options, LEFT_PAD, DESC_PAD);

  if (usage != null && usage.length >= 2) {
    for (int i = 1; i < usage.length; ++i) {
      format.printWrapped(err, WIDTH, LEFT_PAD, usage[i]);
    }
  }
}
 
源代码8 项目: incubator-heron   文件: AbstractTestTopology.java
protected AbstractTestTopology(String[] args) throws MalformedURLException {
  CommandLineParser parser = new DefaultParser();
  HelpFormatter formatter = new HelpFormatter();
  Options options = getArgOptions();

  try {
    cmd = parser.parse(options, args);
  } catch (ParseException e) {
    formatter.setWidth(120);
    formatter.printHelp("java " + getClass().getCanonicalName(), options, true);
    throw new RuntimeException(e);
  }

  this.topologyName = cmd.getOptionValue(TOPOLOGY_OPTION);
  if (cmd.getOptionValue(RESULTS_URL_OPTION) != null) {
    this.httpServerResultsUrl =
        pathAppend(cmd.getOptionValue(RESULTS_URL_OPTION), this.topologyName);
  } else {
    this.httpServerResultsUrl = null;
  }
}
 
源代码9 项目: twister2   文件: NomadWorkerStarter.java
private NomadWorkerStarter(String[] args) {
  Options cmdOptions = null;
  try {
    cmdOptions = setupOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(cmdOptions, args);

    // lets determine the process id
    int rank = 0;

    // load the configuration
    // we are loading the configuration for all the components
    this.config = loadConfigurations(cmd, rank);
    controller = new NomadController(true);
    controller.initialize(config);
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("SubmitterMain", cmdOptions);
    throw new RuntimeException("Error parsing command line options: ", e);
  }
}
 
源代码10 项目: twister2   文件: NomadJobMasterStarter.java
public NomadJobMasterStarter(String[] args) {
  Options cmdOptions = null;
  try {
    cmdOptions = setupOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(cmdOptions, args);

    // lets determine the process id
    int rank = 0;

    // load the configuration
    // we are loading the configuration for all the components
    this.config = loadConfigurations(cmd, rank);
    controller = new NomadController(true);
    controller.initialize(config);
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("SubmitterMain", cmdOptions);
    throw new RuntimeException("Error parsing command line options: ", e);
  }
}
 
源代码11 项目: incubator-retired-blur   文件: TermsDataCommand.java
@SuppressWarnings("static-access")
private static CommandLine parse(String[] otherArgs, Writer out) {
  Options options = new Options();
  options.addOption(OptionBuilder.withArgName("startwith").hasArg().withDescription("The value to start with.")
      .create("s"));
  options.addOption(OptionBuilder.withArgName("size").hasArg().withDescription("The number of terms to return.")
      .create("n"));
  options.addOption(OptionBuilder.withDescription("Get the frequency of each term.").create("F"));

  CommandLineParser parser = new PosixParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, otherArgs);
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out, true);
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, "terms", null, options, HelpFormatter.DEFAULT_LEFT_PAD,
        HelpFormatter.DEFAULT_DESC_PAD, null, false);
    return null;
  }
  return cmd;
}
 
源代码12 项目: tchannel-java   文件: PingServer.java
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("p", "port", true, "Server Port to connect to");
    options.addOption("?", "help", false, "Usage");
    HelpFormatter formatter = new HelpFormatter();

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

    if (cmd.hasOption("?")) {
        formatter.printHelp("PingClient", options, true);
        return;
    }

    int port = Integer.parseInt(cmd.getOptionValue("p", "8888"));

    System.out.println(String.format("Starting server on port: %d", port));
    new PingServer(port).run();
    System.out.println("Stopping server...");
}
 
源代码13 项目: ofexport2   文件: ActiveOptionProcessor.java
@SuppressWarnings("unchecked")
public void printHelp() throws IOException {

    System.out.println (progName.toUpperCase());
    System.out.println();

    try (
        InputStream in = this.getClass().getResourceAsStream("/version.properties")) {
        Properties p = new Properties();
        p.load(in);
        System.out.println ("Version: " + p.getProperty("version"));
        System.out.println ("Build Date: " + p.getProperty("date"));

    }

    System.out.println();

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);
    // Output in the order I specify
    formatter.setOptionComparator((x, y) -> ((ActiveOption<P>) x).getOrder() - ((ActiveOption<P>) y).getOrder());
    formatter.printHelp(progName, options);
}
 
源代码14 项目: hmftools   文件: CountBamLinesApplication.java
public static void main(final String... args) throws IOException, ExecutionException, InterruptedException {
    final Options options = CobaltConfig.createOptions();
    try (final CountBamLinesApplication application = new CountBamLinesApplication(options, args)) {
        application.run();
    } catch (ParseException e) {
        LOGGER.warn(e);
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("CountBamLinesApplication", options);
        System.exit(1);
    }
}
 
源代码15 项目: pravega-samples   文件: ConsoleReader.java
public static void main(String[] args) throws IOException, InterruptedException {
    Options options = getOptions();
    CommandLine cmd = null;
    try {
        cmd = parseCommandLineArgs(options, args);
    } catch (ParseException e) {
        log.info("Exception parsing: {}.", 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);

    StreamManager streamManager = StreamManager.create(controllerURI);
    streamManager.createScope(scope);
    StreamConfiguration streamConfig = StreamConfiguration.builder()
                                                          .scalingPolicy(ScalingPolicy.fixed(1))
                                                          .build();
    streamManager.createStream(scope, streamName, streamConfig);
    streamManager.close();

    ConsoleReader reader = new ConsoleReader(scope, streamName, controllerURI);
    reader.run();
    System.exit(0);
}
 
源代码16 项目: titus-control-plane   文件: AbstractCassTool.java
private void printHelp() {
    PrintWriter writer = new PrintWriter(System.out);
    HelpFormatter formatter = new HelpFormatter();

    writer.println("Usage: CassTool <cmd> [<option1>... ]");
    writer.println();
    writer.println("Commands:");

    commands.forEach((name, cmd) -> {
        writer.println(name + ": " + cmd.getDescription());
        formatter.printOptions(writer, 128, buildOptions(cmd), 4, 4);
        writer.println();
    });
    writer.flush();
}
 
源代码17 项目: Bats   文件: ApexCli.java
@Override
void printUsage(String cmd)
{
  super.printUsage(cmd + ((options == null) ? "" : " [options]"));
  if (options != null) {
    System.out.println("Options:");
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(System.out);
    formatter.printOptions(pw, 80, options, 4, 4);
    pw.flush();
  }
}
 
源代码18 项目: crail   文件: NvmfStorageConstants.java
public static void parseCmdLine(CrailConfiguration crailConfiguration, String[] args) throws IOException {
	NvmfStorageConstants.updateConstants(crailConfiguration);

	if (args != null) {
		Options options = new Options();

		Option bindIp = Option.builder("a").desc("target ip address").hasArg().build();
		if (IP_ADDR == null) {
			bindIp.setRequired(true);
		}
		Option port = Option.builder("p").desc("target port").hasArg().type(Number.class).build();
		Option nqn = Option.builder("nqn").desc("target subsystem NQN").hasArg().build();
		options.addOption(bindIp);
		options.addOption(port);
		options.addOption(nqn);
		CommandLineParser parser = new DefaultParser();
		HelpFormatter formatter = new HelpFormatter();
		CommandLine line = null;
		try {
			line = parser.parse(options, args);
			if (line.hasOption(port.getOpt())) {
				NvmfStorageConstants.PORT = ((Number) line.getParsedOptionValue(port.getOpt())).intValue();
			}
		} catch (ParseException e) {
			System.err.println(e.getMessage());
			formatter.printHelp("NVMe storage tier", options);
			System.exit(-1);
		}
		if (line.hasOption(bindIp.getOpt())) {
			NvmfStorageConstants.IP_ADDR = InetAddress.getByName(line.getOptionValue(bindIp.getOpt()));
		}
		if (line.hasOption(nqn.getOpt())) {
			NvmfStorageConstants.NQN = line.getOptionValue(nqn.getOpt());
		}
	}

	NvmfStorageConstants.verify();
}
 
源代码19 项目: titus-control-plane   文件: CLI.java
private void printHelp() {
    PrintWriter writer = new PrintWriter(System.out);
    HelpFormatter formatter = new HelpFormatter();

    Options common = new Options();
    appendDefaultOptions(common);

    Options connectivity = new Options();
    appendConnectivityOptions(connectivity);

    writer.println("Usage: TitusCLI <cmd> -H <host> [-p <port>] [cmd options] [params]");
    writer.println();
    writer.println("Common options:");
    formatter.printOptions(writer, 128, common, 4, 4);
    writer.println();
    writer.println("Connectivity options:");
    formatter.printOptions(writer, 128, connectivity, 4, 4);
    writer.println();
    writer.println("Available commands:");
    writer.println();

    for (Map.Entry<String, CliCommand> entry : getCommands().entrySet()) {
        CliCommand cliCmd = entry.getValue();
        writer.println(entry.getKey() + " (" + cliCmd.getDescription() + ')');
        formatter.printOptions(writer, 128, cliCmd.getOptions(), 4, 4);
    }
    writer.flush();
}
 
源代码20 项目: big-c   文件: GenericOptionsParser.java
/**
 * Parse the user-specified options, get the generic options, and modify
 * configuration accordingly
 * @param opts Options to use for parsing args.
 * @param conf Configuration to be modified
 * @param args User-specified arguments
 */
private void parseGeneralOptions(Options opts, Configuration conf, 
    String[] args) throws IOException {
  opts = buildGeneralOptions(opts);
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, preProcessForWindows(args), true);
    processGeneralOptions(conf, commandLine);
  } catch(ParseException e) {
    LOG.warn("options parsing failed: "+e.getMessage());

    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("general options are: ", opts);
  }
}
 
源代码21 项目: metron   文件: ParserTopologyCLI.java
public static void main(String[] args) {

    try {
      Options options = new Options();
      final CommandLine cmd = parse(options, args);
      if (cmd.hasOption("h")) {
        final HelpFormatter usageFormatter = new HelpFormatter();
        usageFormatter.printHelp("ParserTopologyCLI", null, options, null, true);
        System.exit(0);
      }
      ParserTopologyCLI cli = new ParserTopologyCLI();
      ParserTopologyBuilder.ParserTopology topology = cli.createParserTopology(cmd);
      String sensorTypes = ParserOptions.SENSOR_TYPES.get(cmd);
      String topologyName = sensorTypes.replaceAll(TOPOLOGY_OPTION_SEPARATOR, STORM_JOB_SEPARATOR);
      if (ParserOptions.TEST.has(cmd)) {
        topology.getTopologyConfig().put(Config.TOPOLOGY_DEBUG, true);
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology(topologyName, topology.getTopologyConfig(), topology.getBuilder().createTopology());
        Utils.sleep(300000);
        cluster.shutdown();
      } else {
        StormSubmitter.submitTopology(topologyName, topology.getTopologyConfig(), topology.getBuilder().createTopology());
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
 
源代码22 项目: devops-cm-client   文件: Commands.java
static void handleHelpOption(String commandName, String header, String args, Options options) {

            String exitCodes = format(
                      "    %d  The request completed successfully.\n"
                    + "    %d  The request did not complete successfully and\n"
                    + "       no more specific return code as defined below applies.\n"
                    + "    %d  Wrong credentials.\n"
                    + "    %d  Intentionally used by --return-code option in order to\n"
                    + "       indicate 'false'. Only available for commands providing\n"
                    + "       the --return-code option.",
                        ExitException.ExitCodes.OK,
                        ExitException.ExitCodes.GENERIC_FAILURE,
                        ExitException.ExitCodes.NOT_AUTHENTIFICATED,
                        ExitException.ExitCodes.FALSE);

            String commonOpts;

            HelpFormatter formatter = new HelpFormatter();

            try( StringWriter commonOptions = new StringWriter();
                 PrintWriter pw = new PrintWriter(commonOptions);) {
                formatter.printOptions(pw, formatter.getWidth(), Command.addOpts(new Options()), formatter.getLeftPadding(), formatter.getDescPadding());
                commonOpts = commonOptions.toString();
            } catch(IOException e) {
                throw new RuntimeException(e);
            }

            String footer = format("%nCOMMON OPTIONS:%n%s%nEXIT CODES%n%s", commonOpts, exitCodes);

            formatter.printHelp(
                    format("<CMD> [COMMON_OPTIONS] %s [SUBCOMMAND_OPTIONS] %s%n%n", 
                            commandName,
                            args != null ? args : ""),
                    format("SUBCOMMAND OPTIONS:%n",header), options, footer);

        }
 
源代码23 项目: ipst   文件: OnlineWorkflowTool.java
private void showHelp(String message, PrintStream err) {
    err.println(message);
    err.println();
    HelpFormatter formatter = new HelpFormatter();
    // it would be nice to have access to the private method
    // eu.itesla_project.commons.tools.Main.printCommandUsage
    formatter.printHelp(80, getCommand().getName(), "", getCommand().getOptions(),
            "\n" + Objects.toString(getCommand().getUsageFooter(), ""), true);
}
 
源代码24 项目: quaerite   文件: CopyIndex.java
public static void main(String[] args) throws Exception {
    CommandLine commandLine = null;

    try {
        commandLine = new DefaultParser().parse(OPTIONS, args);
    } catch (ParseException e) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(
                "java -jar org.mitre.quaerite.cli.DumpResults",
                OPTIONS);
        return;
    }
    SearchClient srcClient = SearchClientFactory.getClient(commandLine.getOptionValue("src"));
    SearchClient destClient = SearchClientFactory.getClient(commandLine.getOptionValue("dest"));
    Set<String> whiteListFields = splitComma(
            getString(commandLine, "whiteListFields", StringUtils.EMPTY));
    Set<String> blackListFields = splitComma(
            getString(commandLine, "blackListFields", StringUtils.EMPTY));
    Set<String> filterQueryStrings = splitComma(
            getString(commandLine, "fq", StringUtils.EMPTY));
    Set<Query> filterQueries = new HashSet<>();
    for (String q : filterQueryStrings) {
        filterQueries.add(new LuceneQuery("", q));
    }

    blackListFields = updateBlackList(srcClient, blackListFields);

    LOG.debug("whiteListFields:" + whiteListFields);
    LOG.debug("blackListFields:" + blackListFields);
    LOG.debug("filterQueries:" + filterQueries);
    CopyIndex copyIndex = new CopyIndex();
    if (commandLine.hasOption("clean")) {
        destClient.deleteAll();
    }
    copyIndex.setNumThreads(getInt(commandLine, "numThreads", NUM_THREADS));
    copyIndex.setBatchSize(getInt(commandLine, "b", BATCH_SIZE));

    copyIndex.execute(srcClient, destClient, filterQueries, whiteListFields,
            blackListFields);
}
 
源代码25 项目: lucene-solr   文件: SolrCLI.java
@Override
public int runTool(CommandLine cli) throws Exception {
  if (cli.getOptions().length == 0 || cli.getArgs().length > 0 || cli.hasOption("h")) {
    new HelpFormatter().printHelp("bin/solr utils [OPTIONS]", getToolOptions(this));
    return 1;
  }
  if (cli.hasOption("s")) {
    serverPath = Paths.get(cli.getOptionValue("s"));
  }
  if (cli.hasOption("l")) {
    logsPath = Paths.get(cli.getOptionValue("l"));
  }
  if (cli.hasOption("q")) {
    beQuiet = cli.hasOption("q");
  }
  if (cli.hasOption("remove_old_solr_logs")) {
    if (removeOldSolrLogs(Integer.parseInt(cli.getOptionValue("remove_old_solr_logs"))) > 0) return 1;
  }
  if (cli.hasOption("rotate_solr_logs")) {
    if (rotateSolrLogs(Integer.parseInt(cli.getOptionValue("rotate_solr_logs"))) > 0) return 1;
  }
  if (cli.hasOption("archive_gc_logs")) {
    if (archiveGcLogs() > 0) return 1;
  }
  if (cli.hasOption("archive_console_logs")) {
    if (archiveConsoleLogs() > 0) return 1;
  }
  return 0;
}
 
源代码26 项目: Flink-CEPplus   文件: CliOptionsParser.java
public static void printHelpGatewayModeGateway() {
	HelpFormatter formatter = new HelpFormatter();
	formatter.setLeftPadding(5);
	formatter.setWidth(80);

	formatter.printHelp(" ", GATEWAY_MODE_GATEWAY_OPTIONS);

	System.out.println();
}
 
源代码27 项目: xml-doclet   文件: XmlDoclet.java
/**
 * Parse the given options.
 * 
 * @param optionsArrayArray
 *            The two dimensional array of options.
 * @return the parsed command line arguments.
 */
public static CommandLine parseCommandLine(String[][] optionsArrayArray) {
	try {
		List<String> argumentList = new ArrayList<String>();
		for (String[] optionsArray : optionsArrayArray) {
			argumentList.addAll(Arrays.asList(optionsArray));
		}

		CommandLineParser commandLineParser = new BasicParser() {
			@Override
			protected void processOption(final String arg, @SuppressWarnings("rawtypes") final ListIterator iter)
					throws ParseException {
				boolean hasOption = getOptions().hasOption(arg);
				if (hasOption) {
					super.processOption(arg, iter);
				}
			}
		};
		CommandLine commandLine = commandLineParser.parse(options, argumentList.toArray(new String[] {}));
		return commandLine;
	} catch (ParseException e) {
		LoggingOutputStream loggingOutputStream = new LoggingOutputStream(log, LoggingLevelEnum.INFO);
		PrintWriter printWriter = new PrintWriter(loggingOutputStream);

		HelpFormatter helpFormatter = new HelpFormatter();
		helpFormatter.printHelp(printWriter, 74, "javadoc -doclet " + XmlDoclet.class.getName() + " [options]",
				null, options, 1, 3, null, false);
		return null;
	}
}
 
源代码28 项目: apimanager-swagger-promote   文件: App.java
private static void printUsage(Options options, String message, String[] args) {
	HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(140);
	String binary;
	// Special handling when called from a Choco-Shiem executable
	if(args!=null && Arrays.asList(args).contains("choco")) {
		binary = "api-import";
	} else {
		String scriptExt = "sh";
		if(System.getProperty("os.name").toLowerCase().contains("win")) scriptExt = "bat";
		binary = "scripts"+File.separator+"api-import."+scriptExt;
	}
	
	formatter.printHelp("API-Import", options, true);
	System.out.println("\n");
	System.out.println("ERROR: " + message);
	System.out.println("\n");
	System.out.println("You may run one of the following examples:");
	System.out.println(binary+" -c samples/basic/minimal-config.json -a ../petstore.json -h localhost -u apiadmin -p changeme");
	System.out.println(binary+" -c samples/basic/minimal-config.json -a ../petstore.json -h localhost -u apiadmin -p changeme -s prod");
	System.out.println(binary+" -c samples/complex/complete-config.json -a ../petstore.json -h localhost -u apiadmin -p changeme");
	System.out.println();
	System.out.println();
	System.out.println("Using parameters provided in properties file stored in conf-folder:");
	System.out.println(binary+" -c samples/basic/minimal-config-api-definition.json -s api-env");
	System.out.println();
	System.out.println("For more information and advanced examples please visit:");
	System.out.println("https://github.com/Axway-API-Management-Plus/apimanager-swagger-promote/tree/develop/modules/swagger-promote-core/src/main/assembly/samples");
	System.out.println("https://github.com/Axway-API-Management-Plus/apimanager-swagger-promote/wiki");
}
 
源代码29 项目: RankPL   文件: RankPL.java
private static void printUsage() {
	HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(160);
	List<String> order = Arrays.asList("source", "r", "t", "c", "d", "m", "f", "ns", "nr", "help");
	formatter.setOptionComparator(new Comparator<Option>() {
		@Override
		public int compare(Option o1, Option o2) {
			String s1 = ((Option) o1).getOpt();
			String s2 = ((Option) o2).getOpt();
			return order.indexOf(s1) - order.indexOf(s2);
		}
	});
	formatter.printHelp("java -jar RankPL.jar", createOptions(), true);
}
 
源代码30 项目: pravega-samples   文件: SecureWriter.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("HelloWorldReader", options);
        System.exit(1);
    }

    final String scope = cmd.getOptionValue("scope") == null ? Constants.DEFAULT_SCOPE : cmd.getOptionValue("scope");
    final String stream = cmd.getOptionValue("stream") == null ? Constants.DEFAULT_STREAM_NAME : cmd.getOptionValue("stream");

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

    final String truststorePath =
            cmd.getOptionValue("truststore") == null ? Constants.DEFAULT_TRUSTSTORE_PATH : cmd.getOptionValue("truststore");
    final boolean validateHostname = cmd.getOptionValue("validatehost") == null ? false : true;

    final String username = cmd.getOptionValue("username") == null ? Constants.DEFAULT_USERNAME : cmd.getOptionValue("username");
    final String password = cmd.getOptionValue("password") == null ? Constants.DEFAULT_PASSWORD : cmd.getOptionValue("password");

    final String routingKey = cmd.getOptionValue("routingKey") == null ? Constants.DEFAULT_ROUTING_KEY : cmd.getOptionValue("routingKey");
    final String message = cmd.getOptionValue("message") == null ? Constants.DEFAULT_MESSAGE : cmd.getOptionValue("message");

    SecureWriter writer = new SecureWriter(scope, stream, controllerURI,
            truststorePath, validateHostname,
            username, password);
    writer.write(routingKey, message);
}