Java Code Examples for org.apache.commons.cli.HelpFormatter
The following examples show how to use
org.apache.commons.cli.HelpFormatter.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: DDMQ Author: didi File: ServerUtil.java License: Apache License 2.0 | 6 votes |
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; }
Example #2
Source Project: quaerite Author: mitre File: WinnowAnalyzedElevate.java License: Apache License 2.0 | 6 votes |
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); }
Example #3
Source Project: hmftools Author: hartwigmedical File: CreateShallowSeqDB.java License: GNU General Public License v3.0 | 6 votes |
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!"); }
Example #4
Source Project: Flink-CEPplus Author: ljygz File: FlinkYarnSessionCli.java License: Apache License 2.0 | 6 votes |
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); }
Example #5
Source Project: hmftools Author: hartwigmedical File: HealthChecksApplication.java License: GNU General Public License v3.0 | 6 votes |
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); }
Example #6
Source Project: hmftools Author: hartwigmedical File: PonApplication.java License: GNU General Public License v3.0 | 6 votes |
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(); } }
Example #7
Source Project: parquet-tools Author: wesleypeck File: Main.java License: Apache License 2.0 | 6 votes |
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]); } } }
Example #8
Source Project: incubator-heron Author: apache File: AbstractTestTopology.java License: Apache License 2.0 | 6 votes |
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; } }
Example #9
Source Project: twister2 Author: DSC-SPIDAL File: NomadWorkerStarter.java License: Apache License 2.0 | 6 votes |
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); } }
Example #10
Source Project: twister2 Author: DSC-SPIDAL File: NomadJobMasterStarter.java License: Apache License 2.0 | 6 votes |
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); } }
Example #11
Source Project: incubator-retired-blur Author: apache File: TermsDataCommand.java License: Apache License 2.0 | 6 votes |
@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; }
Example #12
Source Project: tchannel-java Author: uber File: PingServer.java License: MIT License | 6 votes |
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..."); }
Example #13
Source Project: ofexport2 Author: psidnell File: ActiveOptionProcessor.java License: Apache License 2.0 | 6 votes |
@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); }
Example #14
Source Project: hmftools Author: hartwigmedical File: CountBamLinesApplication.java License: GNU General Public License v3.0 | 5 votes |
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); } }
Example #15
Source Project: pravega-samples Author: pravega File: ConsoleReader.java License: Apache License 2.0 | 5 votes |
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); }
Example #16
Source Project: titus-control-plane Author: Netflix File: AbstractCassTool.java License: Apache License 2.0 | 5 votes |
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(); }
Example #17
Source Project: Bats Author: lealone File: ApexCli.java License: Apache License 2.0 | 5 votes |
@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(); } }
Example #18
Source Project: crail Author: zrlio File: NvmfStorageConstants.java License: Apache License 2.0 | 5 votes |
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(); }
Example #19
Source Project: titus-control-plane Author: Netflix File: CLI.java License: Apache License 2.0 | 5 votes |
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(); }
Example #20
Source Project: big-c Author: yncxcw File: GenericOptionsParser.java License: Apache License 2.0 | 5 votes |
/** * 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); } }
Example #21
Source Project: metron Author: apache File: ParserTopologyCLI.java License: Apache License 2.0 | 5 votes |
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); } }
Example #22
Source Project: devops-cm-client Author: SAP File: Commands.java License: Apache License 2.0 | 5 votes |
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); }
Example #23
Source Project: ipst Author: itesla File: OnlineWorkflowTool.java License: Mozilla Public License 2.0 | 5 votes |
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); }
Example #24
Source Project: quaerite Author: mitre File: CopyIndex.java License: Apache License 2.0 | 5 votes |
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); }
Example #25
Source Project: lucene-solr Author: apache File: SolrCLI.java License: Apache License 2.0 | 5 votes |
@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; }
Example #26
Source Project: Flink-CEPplus Author: ljygz File: CliOptionsParser.java License: Apache License 2.0 | 5 votes |
public static void printHelpGatewayModeGateway() { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); formatter.printHelp(" ", GATEWAY_MODE_GATEWAY_OPTIONS); System.out.println(); }
Example #27
Source Project: xml-doclet Author: MarkusBernhardt File: XmlDoclet.java License: Apache License 2.0 | 5 votes |
/** * 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; } }
Example #28
Source Project: apimanager-swagger-promote Author: Axway-API-Management-Plus File: App.java License: Apache License 2.0 | 5 votes |
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"); }
Example #29
Source Project: RankPL Author: tjitze File: RankPL.java License: MIT License | 5 votes |
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); }
Example #30
Source Project: pravega-samples Author: pravega File: SecureWriter.java License: Apache License 2.0 | 5 votes |
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); }