private void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ls [options] path", options); }
/** * Prints the help message. * * @param message message before standard usage information */ public static void printHelp(String message) { System.err.println(message); HelpFormatter help = new HelpFormatter(); help.printHelp(USAGE, OPTIONS); }
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; }
Options options = new Options(); options.addOption(input); options.addOption(output); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); String inputFilePath = cmd.getOptionValue("input"); String outputFilePath = cmd.getOptionValue("output"); System.out.println(inputFilePath); System.out.println(outputFilePath);
/** * 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(); } }
/** * @param optString may empty str (not null), in which case it's no-op */ public HCatStorer(String partSpecs, String pigSchema, String optString) throws Exception { super(partSpecs, pigSchema); String[] optsArr = optString.split(" "); CommandLine configuredOptions; try { configuredOptions = parser.parse(validOptions, optsArr); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "[-" + ON_OOR_VALUE_OPT + "]", validOptions ); throw e; } Properties udfProps = UDFContext.getUDFContext().getUDFProperties(this.getClass(), new String[]{sign}); //downstream code expects it to be set to a valid value udfProps.put(ON_OORA_VALUE_PROP, configuredOptions.getOptionValue(ON_OOR_VALUE_OPT, getDefaultValue().name())); if(LOG.isDebugEnabled()) { LOG.debug("setting " + configuredOptions.getOptionValue(ON_OOR_VALUE_OPT)); } isValidOOROption((String)udfProps.get(ON_OORA_VALUE_PROP)); } public HCatStorer(String partSpecs, String pigSchema) throws Exception {
/** * Displays the command line help message to the standard output. */ public void printHelp() { final HelpFormatter formatter = new HelpFormatter(); final Options options = new Options(); addStandardOptions(options); if (line != null && line.hasOption(ARGUMENT.ADVANCED_HELP)) { addAdvancedOptions(options); } final String helpMsg = String.format("%n%s" + " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. " + "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n", settings.getString("application.name", "DependencyCheck"), settings.getString("application.name", "DependencyCheck")); formatter.printHelp(settings.getString("application.name", "DependencyCheck"), helpMsg, options, "", true); }
@Test public void testLongLineChunkingIndentIgnored() { Options options = new Options(); options.addOption("x", "extralongarg", false, "This description is Long." ); formatter.printHelp(new PrintWriter(sw), 22, this.getClass().getName(), "Header", options, 0, 5, "Footer"); String expected = "usage:" + CR + " org.apache.comm" + CR + " ons.cli.bug.Bug" + CR + " CLI162Test" + CR + "Header" + CR + "-x,--extralongarg" + CR + " This description is" + CR + " Long." + CR + "Footer" + CR; assertEquals( "Long arguments did not split as expected", expected, sw.toString() ); }
@Test public void testHeaderStartingWithLineSeparator() { // related to Bugzilla #21215 Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); String header = EOL + "Header"; String footer = "Footer"; StringWriter out = new StringWriter(); formatter.printHelp(new PrintWriter(out), 80, "foobar", header, options, 2, 2, footer, true); assertEquals( "usage: foobar" + EOL + "" + EOL + "Header" + EOL + "" + EOL + "Footer" + EOL , out.toString()); }
public static void main(String[] args) throws Exception { RunOptions runOptions; try { Options opts = createOptions(); CommandLine cli = new GnuParser().parse(opts, args); if (cli.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HiveStrictManagedMigration.class.getName(), opts); return; } runOptions = createRunOptions(cli); } catch (Exception err) { throw new Exception("Error processing options", err); } int rc = 0; HiveStrictManagedMigration migration = null; try { migration = new HiveStrictManagedMigration(runOptions); migration.run(); } catch (Exception err) { LOG.error("Failed with error", err); rc = -1; } finally { if (migration != null) { migration.cleanup(); } } // TODO: Something is preventing the process from terminating after main(), adding exit() as hacky solution. System.exit(rc); }
/** * Parse the user-specified options, get the generic options, and modify * configuration accordingly. * * @param opts Options to use for parsing args. * @param args User-specified arguments * @return true if the parse was successful */ private boolean parseGeneralOptions(Options opts, String[] args) throws IOException { opts = buildGeneralOptions(opts); CommandLineParser parser = new GnuParser(); boolean parsed = false; try { commandLine = parser.parse(opts, preProcessForWindows(args), true); processGeneralOptions(commandLine); parsed = true; } catch(ParseException e) { LOG.warn("options parsing failed: "+e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("general options are: ", opts); } return parsed; }
public static void printHelpForInfo() { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5); formatter.setWidth(80); System.out.println("\nAction \"info\" shows the optimized execution plan of the program (JSON)."); System.out.println("\n Syntax: info [OPTIONS] <jar-file> <arguments>"); formatter.setSyntaxPrefix(" \"info\" action options:"); formatter.printHelp(" ", getInfoOptionsWithoutDeprecatedOptions(new Options())); System.out.println(); }
/** * Parse command line. */ public static CommandLine parseCommandLine(Options options, String[] args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cli = parser.parse(options, args); if (cli.hasOption(StressTestUtils.HELP_OPT.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( MRStressTest.class.getSimpleName(), OPTIONS); System.exit(0); } return cli; }
private static void printUsageAndExit(Options options, String message) { System.out.println(message); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("storm-sql-runner ", options); System.exit(1); }
public PhoenixHBaseStorage(String server, String optString) throws ParseException { populateValidOptions(); this.server = server; String[] optsArr = optString == null ? new String[0] : optString.split(" "); try { configuredOptions = parser.parse(validOptions, optsArr); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("[-batchSize]", validOptions); throw e; } batchSize = Long.parseLong(configuredOptions.getOptionValue("batchSize")); }
/** * Prints the usage. */ private static void usage() { new HelpFormatter().printHelp("java -cp alluxio-" + RuntimeConstants.VERSION + "-jar-with-dependencies.jar alluxio.master.journal.JournalTool", "Read an Alluxio journal and write it to stdout in a human-readable format.", OPTIONS, "", true); } }
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); if (ParserOptions.TEST.has(cmd)) { topology.getTopologyConfig().put(Config.TOPOLOGY_DEBUG, true); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(sensorTypes.replaceAll(",", STORM_JOB_SEPARATOR), topology.getTopologyConfig(), topology.getBuilder().createTopology()); Utils.sleep(300000); cluster.shutdown(); } else { StormSubmitter.submitTopology(sensorTypes.replaceAll(",", STORM_JOB_SEPARATOR), topology.getTopologyConfig(), topology.getBuilder().createTopology()); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
@Test public void testInfiniteLoop() { Options options = new Options(); options.addOption("h", "help", false, "This is a looooong description"); // used to hang & crash formatter.printHelp(new PrintWriter(sw), 20, "app", null, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null); String expected = "usage: app" + CR + " -h,--help This is" + CR + " a" + CR + " looooon" + CR + " g" + CR + " descrip" + CR + " tion" + CR; assertEquals(expected, sw.toString()); }
@Test public void testIndentedHeaderAndFooter() { // related to CLI-207 Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); String header = " Header1\n Header2"; String footer = " Footer1\n Footer2"; StringWriter out = new StringWriter(); formatter.printHelp(new PrintWriter(out), 80, "foobar", header, options, 2, 2, footer, true); assertEquals( "usage: foobar" + EOL + " Header1" + EOL + " Header2" + EOL + "" + EOL + " Footer1" + EOL + " Footer2" + EOL , out.toString()); }
public JmxTransConfiguration parseOptions(@Nonnull String[] args) throws OptionsException, org.apache.commons.cli.ParseException { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(getOptions(), args); Option[] options = cl.getOptions(); configuration.setAdditionalJars(option.getValuesList()); } else if (option.getOpt().equals("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar jmxtrans-all.jar", getOptions()); configuration.setHelp(true);