List of usage examples for org.apache.commons.cli HelpFormatter setOptPrefix
public void setOptPrefix(String prefix)
From source file:com.quanticate.opensource.pdftkbox.PDFtkBox.java
protected static void doPrintHelp(Options optsHelp, Options optsNormal, Options optsPDFtk) { // Some general stuff System.out.println("Imports or Exports Bookmarks from a PDF file"); System.out.println();/* www . j ava2 s. c o m*/ // Output the normal help HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PDFtkBox", optsNormal, true); System.out.println(); // Output the PDFtk-style help formatter.setOptPrefix(""); formatter.printHelp("PDFtkBox <pdf> [dump_data | update_info <bookmarks>] output <pdf>", optsPDFtk, false); // Ignore the opts help }
From source file:com.eucalyptus.upgrade.TestHarness.java
@SuppressWarnings({ "static-access" }) private static void printHelp(Options opts) { try {//from w w w . j a va 2 s .c o m PrintWriter out = new PrintWriter(System.out); HelpFormatter help = new HelpFormatter(); help.setArgName("TESTS"); help.printHelp(out, LINE_BYTES, "java -jar test.jar", "Options controlling the test harness.", opts, 2, 4, "", true); Multimap<Class, Method> testMethods = getTestMethods(); help = new HelpFormatter(); help.setLongOptPrefix(""); help.setOptPrefix(""); help.setSyntaxPrefix(""); help.setLeftPadding(0); Options testOptions = new Options(); for (Class c : testMethods.keySet()) { testOptions.addOption( OptionBuilder.withDescription(getDescription(c)).withLongOpt(c.getSimpleName()).create()); for (Method m : testMethods.get(c)) { testOptions.addOption(OptionBuilder.withDescription(getDescription(m)) .withLongOpt(c.getSimpleName() + "." + m.getName()).create()); } } help.printHelp(out, LINE_BYTES, " ", "Tests:", testOptions, 0, 2, "", false); out.flush(); } catch (Exception e) { System.out.println(e); System.exit(1); } }
From source file:chiliad.parser.pdf.cli.ParserCli.java
public void showHelpMessage() { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(new FixedOrderComparator(options.getOptions().toArray())); helpFormatter.setOptPrefix(optionPrefix); helpFormatter.printHelp(helpMessage, options); }
From source file:org.apparatus_templi.Coordinator.java
/** * Parse all command line arguments. Any preferences read from the command like will be put into * the {@link Prefs} singleton./*from ww w . j av a 2 s.c om*/ * * @param argv * the command line arguments to be parsed */ private static void parseCommandLineOptions(String[] argv) { assert argv != null : "command line arguments should never be null"; // Using apache commons cli to parse the command line options Options options = new Options(); options.addOption("help", false, "Display this help message."); // the commons cli parser does not allow '.' within the option names, so we have to replace // the periods with underscores for now. When parsing the args later the underscores will be // converted back to proper dot notation for (String key : prefs.getDefPreferencesMap().keySet()) { String optName; if (key.contains(".")) { optName = key.replaceAll("\\.", "_"); } else { optName = key; } options.addOption(OptionBuilder.withArgName(optName).hasArg() .withDescription(prefs.getPreferenceDesc(key)).create(optName)); } CommandLineParser cliParser = new org.apache.commons.cli.PosixParser(); try { CommandLine cmd = cliParser.parse(options, argv); if (cmd.hasOption("help")) { // show help message and exit HelpFormatter formatter = new HelpFormatter(); formatter.setOptPrefix("--"); formatter.setLongOptPrefix("--"); formatter.printHelp(TAG, options); System.exit(0); } // Load the configuration file URI String configFile; if (cmd.hasOption(Prefs.Keys.configFile)) { configFile = cmd.getOptionValue(Prefs.Keys.configFile); if (configFile.startsWith("~" + File.separator)) { configFile = System.getProperty("user.home") + configFile.substring(1); } } else { configFile = prefs.getDefPreference(Prefs.Keys.configFile); } prefs.putPreference(Prefs.Keys.configFile, configFile); // Read in preferences from the config file prefs.readPreferences(configFile); // Read in preferences from the command line options for (Option opt : cmd.getOptions()) { // Apache CLI parser does not allow '.' within option names, so we have to convert // all '_' back to the '.' notation String key = opt.getArgName().replace("_", "."); String value = opt.getValue(); prefs.putPreference(key, value); } } catch (ParseException e) { System.out.println("Error processing options: " + e.getMessage()); new HelpFormatter().printHelp("Diff", options); Coordinator.exitWithReason("Error parsing command line options"); } }
From source file:org.kaazing.gateway.server.WindowsMain.java
/** * @param args// ww w. java 2 s. co m */ public static void main(String... args) throws Exception { // Rather than writing a completely separate parser, we're going to // transform the arguments that we have so they appear to be in the // right format. Specifically, if we get an argument of the form // '/xxx=yyy', we'll substitute '--' for '/'. It turns out that .bat // files actually replace '=' with space, which is what we want. // Unfortunately we can't easily handle the ':' case quite so easily, // (though product management has said they're okay with that.) HelpFormatter formatter = new HelpFormatter(); formatter.setLongOptPrefix("/"); formatter.setOptPrefix("/"); for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.startsWith("/")) { if (arg.length() == 1) { arg = "-"; } else { arg = "--" + arg.substring(1); } } args[i] = arg; } GatewayCommandLineProcessor gatewayCommandLineProcessor = new GatewayCommandLineProcessor(formatter); gatewayCommandLineProcessor.launchGateway(args); }
From source file:org.kalaider.desktop.scheduler.runner.Runner.java
private static void help(ParseException ex) { if (ex != null) LOG.error("Illegal command.", ex.getMessage()); HelpFormatter fmt = new HelpFormatter(); fmt.setLongOptPrefix("-"); fmt.setOptPrefix("-"); fmt.printHelp(" ", options); }
From source file:org.openanzo.client.cli.CommandLineInterface.java
static void printHelp(IConsole consoleWriter) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptPrefix(""); String syntax = "anzo <subcommand> [options] [args]"; String header = generateVersionHeader(); header += "\n\nType 'anzo help <subcommand>' for help with a specific subcommand."; header += "\n\nAvailable subcommands:"; String footer = "URI arguments to commands may either be fully qualified URIs (\"http://...\") or prefixed URIs (\"dc:title\"). "; footer += "The prefix mapping is defined in the users settings file."; footer += "\n\nUser settings are loaded from a user's \"~/.anzo/settings.trig\" file."; footer += "\n\nRDF format options are: " + CommandLineInterface.getRDFFormatOptionsString(); footer += "See documentation for details."; Options options = new Options(); for (SubCommand command : subcommands) { options.addOption(new Option(command.getName(), "")); }//ww w. ja v a 2s .c o m formatter.printHelp(syntax, header, options, footer); }
From source file:org.rhq.metrics.simulator.SimulatorCLI.java
public void printUsage() { HelpFormatter helpFormatter = new HelpFormatter(); String syntax = "rhq-ms [options]"; String header = ""; helpFormatter.setOptPrefix(""); helpFormatter.printHelp(syntax, header, options, null); }
From source file:org.rhq.server.control.RHQControl.java
public void printUsage() { HelpFormatter helpFormatter = new HelpFormatter(); String syntax = "rhqctl <cmd> [options]"; String header = "\nwhere <cmd> is one of:"; String footer = "\n* For help on a specific command: rhqctl <cmd> --help\n" // + "\n* Limit commands to a single component with one of: --storage, --server, --agent"; helpFormatter.setOptPrefix(""); helpFormatter.printHelp(syntax, header, commands.getOptions(), footer); }
From source file:uk.ac.imperial.presage2.core.cli.Presage2CLI.java
protected void printHelp() { HelpFormatter formatter = new HelpFormatter(); Options cmdOpts = new Options(); cmdOpts.addOptionGroup(getCommands()); formatter.setOptPrefix(""); formatter.printHelp("presage2-cli <command> [OPTIONS]", cmdOpts); }