List of usage examples for org.apache.commons.cli HelpFormatter printUsage
public void printUsage(PrintWriter pw, int width, String app, Options options)
Prints the usage statement for the specified application.
From source file:org.apache.tajo.cli.tsql.TajoCli.java
private void printUsage() { HelpFormatter formatter = new HelpFormatter(); formatter.printUsage(this.serr, 80, "tsql [options] [database]", options); }
From source file:org.codeseed.common.config.ext.CommandLineHelper.java
/** * Returns a property source from the supplied command line arguments. * * @param args// w ww . jav a 2s . c o m * the arguments passed from the command line * @return a property source backed by the parsed command line arguments */ public PropertySource parse(String[] args) { // Construct the command line options final Options options = this.options.build(); if (helpOption != null) { options.addOption(helpOption); } try { final CommandLine commandLine = parser.parse(options, args); if (helpOption != null && commandLine.hasOption(helpOption.getOpt())) { // Display the help HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(syntaxPrefix()); help.setLongOptPrefix(" --"); help.printHelp(err, terminalWidth, applicationName(), header(), options, 1, 1, footer(), true); return helpExit(); } else { // Wrapped the parsed commands in a property source return new CommandLinePropertySource(commandLine); } } catch (ParseException e) { // Display the error and usage message HelpFormatter help = new HelpFormatter(); help.printWrapped(err, terminalWidth, e.getMessage()); help.printUsage(err, terminalWidth, applicationName(), options); throw usageExit(e); } }
From source file:org.deegree.commons.tools.CommandUtils.java
/** * Prints a help message for a apache commons-cli based command line tool and <b>terminates the programm</b>. * //from ww w.j av a 2s .co m * @param options * the options to generate help/usage information for * @param toolName * the name of the command line tool * @param helpMsg * some further information * @param otherUsageInfo * an optional string to append to the usage information (e.g. for additional arguments like input files) */ public static void printHelp(Options options, String toolName, String helpMsg, String otherUsageInfo) { HelpFormatter formatter = new HelpFormatter(); StringWriter helpWriter = new StringWriter(); StringBuffer helpBuffer = helpWriter.getBuffer(); PrintWriter helpPrintWriter = new PrintWriter(helpWriter); helpPrintWriter.println(); if (helpMsg != null && helpMsg.length() != 0) { formatter.printWrapped(helpPrintWriter, HELP_TEXT_WIDTH, helpMsg); helpPrintWriter.println(); } formatter.printUsage(helpPrintWriter, HELP_TEXT_WIDTH, toolName, options); if (otherUsageInfo != null) { helpBuffer.deleteCharAt(helpBuffer.length() - 1); // append additional arguments helpBuffer.append(' ').append(otherUsageInfo).append("\n"); } helpBuffer.append("\n"); formatter.printOptions(helpPrintWriter, HELP_TEXT_WIDTH, options, 3, 5); System.err.print(helpBuffer.toString()); System.exit(1); }
From source file:org.dfotos.rssfilter.App.java
/** * Prints "help" to the System.out.//from w w w .j a va 2 s .c o m * @param options Our command line options. */ private static void printHelp(final Options options) { System.out.println(""); HelpFormatter formatter = new HelpFormatter(); PrintWriter pw1 = new MyPrintWriter(System.out); pw1.print(" "); formatter.printUsage(pw1, formatter.getWidth(), "rss-filter", options); pw1.println(" <command> [command2] [command3] ... [commandN]"); pw1.flush(); System.out.println("\n\n Commands:"); COMMANDS.keySet(); for (String cmd : COMMANDS.keySet()) { String tabs = "\t\t"; if (cmd.length() > 6) { tabs = "\t"; } System.out.println(" " + cmd + tabs + COMMANDS.get(cmd).getHelpStr()); } System.out.println("\n Options:"); PrintWriter pw2 = new PrintWriter(System.out); formatter.printOptions(pw2, formatter.getWidth(), options, formatter.getLeftPadding(), formatter.getDescPadding()); pw2.flush(); System.out.println("\n Example:"); System.out.println(" rss-filter -v get tag export \n"); }
From source file:org.jboss.security.fips.utils.FIPSVaultOptions.java
/** * Print the help for the command line options. *///from w ww. j a v a 2 s. c om public void printUsage() { HelpFormatter formatter = new HelpFormatter(); PrintWriter pw = new PrintWriter(System.err); formatter.printUsage(pw, HELP_WIDTH, APP_NAME, options); }
From source file:org.jcryptool.commands.core.ProxiedCommand.java
/** * Generates a syntax term for a command * * @param commandName the name of the command * @param options the options of this command * @return/*w w w. ja v a2 s .c o m*/ */ private static String getSyntaxTerm(String commandName, Options options) { HelpFormatter formatter = new HelpFormatter(); StringWriter writer = new StringWriter(); formatter.printUsage(new PrintWriter(writer), Command.CONSOLE_WIDTH, commandName, options); return writer.toString().replaceAll("\\Ausage:?( )*", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:org.sybila.parasim.application.ParasimOptions.java
public static void printHelp(PrintStream out) { PrintWriter output = new PrintWriter(out); output.println();//from w w w . ja va2s. co m HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printUsage(output, HelpFormatter.DEFAULT_WIDTH, "parasim", getOptions()); output.println(); helpFormatter.printOptions(output, HelpFormatter.DEFAULT_WIDTH, getOptions(), HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD); output.println(); output.flush(); }
From source file:org.vetmeduni.tools.AbstractTool.java
/** * Print the usage with an error message * * @param error the error message//from www .j a v a2s. com */ protected void printUsage(String error) { HelpFormatter formatter = new HelpFormatter(); PrintWriter writer = new PrintWriter(System.err); formatter.printUsage(writer, formatter.getWidth(), usage(), programOptions()); writer.println("error: " + error); writer.close(); }
From source file:ru.jilime.documentum.Monitor.java
public static void printUsage(final Options options, final OutputStream out) { final PrintWriter writer = new PrintWriter(out); final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printUsage(writer, 80, Monitor.class.getName(), options); writer.close();/*from ww w . jav a 2 s. c o m*/ }