Java Code Examples for org.apache.commons.cli.HelpFormatter#printHelp()
The following examples show how to use
org.apache.commons.cli.HelpFormatter#printHelp() .
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 File: CliFrontendParser.java From flink with Apache License 2.0 | 6 votes |
/** * Prints custom cli options. * @param formatter The formatter to use for printing * @param runOptions True if the run options should be printed, False to print only general options */ private static void printCustomCliOptions( Collection<CustomCommandLine> customCommandLines, HelpFormatter formatter, boolean runOptions) { // prints options from all available command-line classes for (CustomCommandLine cli: customCommandLines) { formatter.setSyntaxPrefix(" Options for " + cli.getId() + " mode:"); Options customOpts = new Options(); cli.addGeneralOptions(customOpts); if (runOptions) { cli.addRunOptions(customOpts); } formatter.printHelp(" ", customOpts); System.out.println(); } }
Example 2
Source File: CreateShallowSeqDB.java From hmftools with 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 3
Source File: ConsoleRSAKeyPairGenerator.java From java-license-manager with Apache License 2.0 | 6 votes |
private void printHelp(final HelpFormatter formatter, final Options options) { final OutputStreamWriter streamWriter = new OutputStreamWriter(this.device.out(), LicensingCharsets.UTF_8); final PrintWriter printWriter = new PrintWriter(streamWriter); formatter.printHelp( printWriter, ConsoleRSAKeyPairGenerator.CLI_WIDTH, ConsoleRSAKeyPairGenerator.USAGE, null, options, ConsoleRSAKeyPairGenerator.HELP_DISPLAY_LEFT_PAD, ConsoleRSAKeyPairGenerator.HELP_DISPLAY_DESC_PAD, null, false ); printWriter.close(); try { streamWriter.close(); } catch(final IOException e) { e.printStackTrace(this.device.err()); } }
Example 4
Source File: CliFrontendParser.java From flink with Apache License 2.0 | 5 votes |
public static void printHelpForSavepoint(Collection<CustomCommandLine> customCommandLines) { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); System.out.println("\nAction \"savepoint\" triggers savepoints for a running job or disposes existing ones."); System.out.println("\n Syntax: savepoint [OPTIONS] <Job ID> [<target directory>]"); formatter.setSyntaxPrefix(" \"savepoint\" action options:"); formatter.printHelp(" ", getSavepointOptionsWithoutDeprecatedOptions(new Options())); printCustomCliOptions(customCommandLines, formatter, false); System.out.println(); }
Example 5
Source File: IntegrationTest.java From djl with Apache License 2.0 | 5 votes |
public boolean runTests(String[] args) { Options options = Arguments.getOptions(); try { DefaultParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args, null, false); Arguments arguments = new Arguments(cmd); Duration duration = Duration.ofMinutes(arguments.getDuration()); List<TestClass> tests = listTests(arguments, source); boolean testsPassed = true; while (!duration.isNegative()) { long begin = System.currentTimeMillis(); testsPassed = testsPassed && runTests(tests); long delta = System.currentTimeMillis() - begin; duration = duration.minus(Duration.ofMillis(delta)); } return testsPassed; } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(1); formatter.setWidth(120); formatter.printHelp(e.getMessage(), options); return false; } catch (Throwable t) { logger.error("Unexpected error", t); return false; } }
Example 6
Source File: CliOptionsParser.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static void printHelpEmbeddedModeClient() { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); System.out.println("\nMode \"embedded\" submits Flink jobs from the local machine."); System.out.println("\n Syntax: embedded [OPTIONS]"); formatter.setSyntaxPrefix(" \"embedded\" mode options:"); formatter.printHelp(" ", EMBEDDED_MODE_CLIENT_OPTIONS); System.out.println(); }
Example 7
Source File: CliFrontendParser.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static void printHelpForStop(Collection<CustomCommandLine<?>> customCommandLines) { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); System.out.println("\nAction \"stop\" stops a running program (streaming jobs only)."); System.out.println("\n Syntax: stop [OPTIONS] <Job ID>"); formatter.setSyntaxPrefix(" \"stop\" action options:"); formatter.printHelp(" ", getStopOptionsWithoutDeprecatedOptions(new Options())); printCustomCliOptions(customCommandLines, formatter, false); System.out.println(); }
Example 8
Source File: ResolveUrls.java From anthelion with Apache License 2.0 | 5 votes |
/** * Runs the resolve urls tool. */ public static void main(String[] args) { Options options = new Options(); Option helpOpts = OptionBuilder.withArgName("help").withDescription( "show this help message").create("help"); Option urlOpts = OptionBuilder.withArgName("urls").hasArg().withDescription( "the urls file to check").create("urls"); Option numThreadOpts = OptionBuilder.withArgName("numThreads").hasArgs().withDescription( "the number of threads to use").create("numThreads"); options.addOption(helpOpts); options.addOption(urlOpts); options.addOption(numThreadOpts); CommandLineParser parser = new GnuParser(); try { // parse out common line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help") || !line.hasOption("urls")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ResolveUrls", options); return; } // get the urls and the number of threads and start the resolver String urls = line.getOptionValue("urls"); int numThreads = 100; String numThreadsStr = line.getOptionValue("numThreads"); if (numThreadsStr != null) { numThreads = Integer.parseInt(numThreadsStr); } ResolveUrls resolve = new ResolveUrls(urls, numThreads); resolve.resolveUrls(); } catch (Exception e) { LOG.error("ResolveUrls: " + StringUtils.stringifyException(e)); } }
Example 9
Source File: ServerUtil.java From rocketmq with Apache License 2.0 | 4 votes |
public static void printCommandLineHelp(final String appName, final Options options) { HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); hf.printHelp(appName, options, true); }
Example 10
Source File: ApplicationArguments.java From bigtable-sql with Apache License 2.0 | 4 votes |
void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("squirrel-sql", _options); }
Example 11
Source File: MetaGenerator.java From TypeScript-Microservices with MIT License | 4 votes |
static void usage(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("MetaGenerator. Generator for creating a new template set " + "and configuration for Codegen. The output will be based on the language you " + "specify, and includes default templates to include.", options); }
Example 12
Source File: CommandArgs.java From gdx-proto with Apache License 2.0 | 4 votes |
public static ScreenSize process(String[] args) { Options options = new Options(); options.addOption("s", "server", false, "start online server"); options.addOption("p", "port", true, "specify TCP port to either host on (server) or connect to (client)"); options.addOption("c", "client", false, "connect to server as a client"); options.addOption("a", "address", true, "supply hostname address to connect to"); options.addOption("d", "lag-delay", true, "simulate lag with argument = milliseconds of lag"); options.addOption("z", "screensize", true, "supply screen size in the form of WIDTHxHEIGHT, i.e. 1920x1080"); options.addOption("h", "help", false, "print help"); boolean printHelpAndQuit = false; ScreenSize screenSize = null; CommandLineParser parser = new BasicParser(); CommandLine cli = null; try { cli = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); printHelpAndQuit = true; } if (cli != null && cli.hasOption('h')) { printHelpAndQuit = true; } if (cli != null && cli.getOptions().length == 0) { Main.serverType = ServerType.Local; Main.hasClient = true; } else if (cli != null && !printHelpAndQuit) { if (cli.hasOption('z')) { String[] pieces = cli.getOptionValue('z').split("x"); int width = Integer.parseInt(pieces[0]); int height = Integer.parseInt(pieces[1]); screenSize = new ScreenSize(); screenSize.width = width; screenSize.height = height; } if (cli.hasOption('s')) { Main.serverType = ServerType.Online; System.out.println("server type: online"); } if (cli.hasOption('l')) { if (Main.serverType != null) { System.out.println("please choose local or online server, not both"); printHelpAndQuit = true; } else { Main.serverType = ServerType.Local; } } if (cli.hasOption('c')) { Main.hasClient = true; } if (cli.hasOption('a')) { String value = cli.getOptionValue('a'); if (value != null) { NetManager.host = value; } } if (cli.hasOption('p')) { int port = Integer.parseInt(cli.getOptionValue('p')); NetManager.tcpPort = port; } if (cli.hasOption('d')) { NetServer.simulateLag = true; int lagMillis = Integer.parseInt(cli.getOptionValue('d')); NetServer.lagMin = lagMillis; NetServer.lagMax = lagMillis; } // verify if (!Main.isClient() && !Main.isServer()) { System.out.println("please choose client and server options"); printHelpAndQuit = true; } } if (printHelpAndQuit) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar myjarfile.jar <args>", options); System.exit(1); } return screenSize; }
Example 13
Source File: SentryShellCommon.java From incubator-sentry with Apache License 2.0 | 4 votes |
private void usage(Options sentryOptions) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sentryShell", sentryOptions); }
Example 14
Source File: CrailFsck.java From crail with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { String type = ""; String filename = "/tmp.dat"; long offset = 0; long length = 1; boolean randomize = false; int storageClass = 0; int locationClass = 0; Option typeOption = Option.builder("t").desc("type of experiment [getLocations|directoryDump|namenodeDump|blockStatistics|ping|createDirectory]").hasArg().build(); Option fileOption = Option.builder("f").desc("filename").hasArg().build(); Option offsetOption = Option.builder("y").desc("offset into the file").hasArg().build(); Option lengthOption = Option.builder("l").desc("length of the file [bytes]").hasArg().build(); Option storageOption = Option.builder("c").desc("storageClass for file [1..n]").hasArg().build(); Option locationOption = Option.builder("p").desc("locationClass for file [1..n]").hasArg().build(); Options options = new Options(); options.addOption(typeOption); options.addOption(fileOption); options.addOption(offsetOption); options.addOption(lengthOption); options.addOption(storageOption); options.addOption(locationOption); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length)); if (line.hasOption(typeOption.getOpt())) { type = line.getOptionValue(typeOption.getOpt()); } if (line.hasOption(fileOption.getOpt())) { filename = line.getOptionValue(fileOption.getOpt()); } if (line.hasOption(offsetOption.getOpt())) { offset = Long.parseLong(line.getOptionValue(offsetOption.getOpt())); } if (line.hasOption(lengthOption.getOpt())) { length = Long.parseLong(line.getOptionValue(lengthOption.getOpt())); } if (line.hasOption(storageOption.getOpt())) { storageClass = Integer.parseInt(line.getOptionValue(storageOption.getOpt())); } if (line.hasOption(locationOption.getOpt())) { locationClass = Integer.parseInt(line.getOptionValue(locationOption.getOpt())); } CrailFsck fsck = new CrailFsck(); if (type.equals("getLocations")){ fsck.getLocations(filename, offset, length); } else if (type.equals("directoryDump")){ fsck.directoryDump(filename, randomize); } else if (type.equals("namenodeDump")){ fsck.namenodeDump(); } else if (type.equals("blockStatistics")){ fsck.blockStatistics(filename); } else if (type.equals("ping")){ fsck.ping(); } else if (type.equals("createDirectory")){ fsck.createDirectory(filename, storageClass, locationClass); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("crail fsck", options); System.exit(-1); } }
Example 15
Source File: DumpResults.java From quaerite with Apache License 2.0 | 4 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; } Path outputDir = Paths.get(commandLine.getOptionValue("d")); Path dbDir = Paths.get(commandLine.getOptionValue("db")); Set<String> scorers = new TreeSet<>(); if (commandLine.hasOption("s")) { scorers.addAll( Arrays.asList(commandLine.getOptionValue("s").split(","))); } List<String> querySets = new ArrayList<>(); if (commandLine.hasOption("q")) { querySets.addAll( Arrays.asList(commandLine.getOptionValue("q").split(",")) ); } else { querySets.add(""); } Files.createDirectories(outputDir); List<Scorer> targetScorers = new ArrayList<>(); try (ExperimentDB experimentDB = ExperimentDB.open(dbDir)) { if (scorers.size() == 0) { targetScorers.addAll(experimentDB.getExperiments().getScorers()); } else { for (Scorer scorer : experimentDB.getExperiments().getScorers()) { if (scorers.contains(scorer.getName())) { targetScorers.add(scorer); } } } dumpResults(experimentDB.getExperiments(), experimentDB, querySets, targetScorers, outputDir, false); } }
Example 16
Source File: SentryConfigTool.java From incubator-sentry with Apache License 2.0 | 4 votes |
private void usage(Options sentryOptions) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sentry --command config-tool", sentryOptions); System.exit(-1); }
Example 17
Source File: DatasetCleanerCli.java From incubator-gobblin with Apache License 2.0 | 4 votes |
private void printUsage(Options options) { HelpFormatter formatter = new HelpFormatter(); String usage = "DatasetCleaner configuration "; formatter.printHelp(usage, options); }
Example 18
Source File: Main.java From yangtools with Eclipse Public License 1.0 | 4 votes |
private static void printHelp(final Options options, final HelpFormatter formatter) { formatter.printHelp("yang-system-test [OPTION...] YANG-FILE...", options); }
Example 19
Source File: CWLExecLauncher.java From cwlexec with Apache License 2.0 | 4 votes |
private void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator((o1, o2) -> optionIndex.get(o1) - optionIndex.get(o2)); formatter.printHelp(200, ResourceLoader.getMessage("cwl.command.usage"), null, options, null); }
Example 20
Source File: Validator.java From metadata-qa-marc with GNU General Public License v3.0 | 4 votes |
public void printHelp(Options opions) { HelpFormatter formatter = new HelpFormatter(); String message = String.format("java -cp metadata-qa-marc.jar %s [options] [file]", this.getClass().getCanonicalName()); formatter.printHelp(message, options); }