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:com.fuerve.villageelder.client.commandline.commands.Command.java
/** * Prints a usage message to a given output {@link Writer} * Stolen shamelessly from http://marxsoftware.blogspot.com/2008/11/command-line-parsing-with-apache.html * /*from w w w. ja v a 2 s.c o m*/ * @param writer The {@link Writer} to which the usage information * shall be printed. */ public void printUsage(final Writer writer) { final PrintWriter printWriter = new PrintWriter(writer); final HelpFormatter formatter = new HelpFormatter(); formatter.printUsage(printWriter, 80, getCommandName(), options); printWriter.close(); }
From source file:net.freehal.ui.common.Main.java
private void printHelp(Options options) { final String header = "FreeHAL is a self-learning conversation simulator, " + "an artificial intelligence " + "which uses semantic nets to organize its knowledge."; final String footer = "Please report bugs to <info@freehal.net>."; final int width = 120; final int descPadding = 5; final PrintWriter out = new PrintWriter(System.out, true); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(width);//from w ww. ja v a 2 s .c om formatter.setDescPadding(descPadding); formatter.printUsage(out, width, "java " + Main.class.getName(), options); formatter.printWrapped(out, width, header); formatter.printWrapped(out, width, ""); formatter.printOptions(out, width, options, formatter.getLeftPadding(), formatter.getDescPadding()); formatter.printWrapped(out, width, ""); formatter.printWrapped(out, width, footer); }
From source file:info.mikaelsvensson.devtools.analysis.shared.CommandLineUtil.java
public CommandLine parseArgs(String[] args, String usageHelp, Class<?> appClass, Option... opts) throws CommandLineException { final Options options = new Options(); try {/* www . j a va 2 s .c o m*/ for (Option opt : opts) { options.addOption(opt); } CommandLineParser commandLineParser = new GnuParser(); final CommandLine commandLine = commandLineParser.parse(options, args); return commandLine; } catch (ParseException e) { StringWriter writer = new StringWriter(); final PrintWriter pw = new PrintWriter(writer); pw.println("ERROR:"); pw.println(e.getMessage()); HelpFormatter helpFormatter = new HelpFormatter(); pw.println(); pw.println("ABOUT:"); final int consoleWidth = 120; helpFormatter.printWrapped(pw, consoleWidth, usageHelp); pw.println(); helpFormatter.printUsage(pw, consoleWidth, "java " + appClass.getName(), options); pw.println(); pw.println("ARGUMENTS:"); helpFormatter.printOptions(pw, consoleWidth, options, 0, 1); pw.close(); throw new CommandLineException("Could not parse command line", writer.toString(), e); } }
From source file:nl.cyso.vcloud.client.docs.ManPage.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append(".SH SYNOPSIS\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(ModeType.ROOT)); section.append(str.toString() + "\n"); for (ModeType m : ModeType.values()) { if (m == ModeType.ROOT) { continue; }/*from w w w . j a v a 2s .co m*/ section.append(String.format(".B %s\n", m.toString())); str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(m)); section.append(".RS 4\n"); section.append(str.toString() + "\n"); section.append(".RE\n"); } return section.toString().replace("-", "\\-"); }
From source file:nl.cyso.vcloud.client.docs.Readme.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append("SYNOPSIS\n"); section.append("--------\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(ModeType.ROOT)); section.append("\t\n\t" + str.toString() + "\n"); for (ModeType m : ModeType.values()) { if (m == ModeType.ROOT) { continue; }//from www . j ava2 s . c om str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(m)); section.append(String.format("**%s**\n\n", m.toString())); section.append("\t" + str.toString() + "\n"); } return section.toString(); }
From source file:nl.cyso.vsphere.client.docs.ManPage.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append(".SH SYNOPSIS\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.getVersion().getProjectName(), ConfigModes.getMode("ROOT")); section.append(str.toString() + "\n"); for (String m : ConfigModes.getModes().keySet()) { if (m == "ROOT") { continue; }/*from w w w . j a v a 2s . com*/ section.append(String.format(".B %s\n", m.toString())); str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.getVersion().getProjectName(), ConfigModes.getMode(m)); section.append(".RS 4\n"); section.append(str.toString() + "\n"); section.append(".RE\n"); } return section.toString().replace("-", "\\-"); }
From source file:nl.cyso.vsphere.client.docs.Readme.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append("SYNOPSIS\n"); section.append("--------\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.getVersion().getProjectName(), ConfigModes.getMode("ROOT")); section.append("\t\n\t" + str.toString() + "\n"); for (String m : ConfigModes.getModes().keySet()) { if (m == "ROOT") { continue; }//from w w w.j a v a 2 s . c o m str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.getVersion().getProjectName(), ConfigModes.getMode(m)); section.append(String.format("**%s**\n\n", m.toString())); section.append("\t" + str.toString() + "\n"); } return section.toString(); }
From source file:org.apache.flex.compiler.clients.ASC.java
private void printUsage(String commandLine) { PrintWriter pw = new PrintWriter(out); pw.println();/*from ww w. j a v a 2s . com*/ HelpFormatter formatter = new HelpFormatter(); formatter.printUsage(pw, 72, commandLine, ASC_OPTIONS); pw.println(" FILENAME..."); pw.flush(); }
From source file:org.apache.gobblin.cluster.SingleTaskRunnerMainOptions.java
private void printUsage(final Options options) { final HelpFormatter formatter = new HelpFormatter(); formatter.printUsage(this.writer, CHARACTERS_PER_LINE, SingleTaskRunnerMain.class.getSimpleName(), options); }
From source file:org.apache.stratos.adc.mgt.cli.StratosApplication.java
/** * Print "usage"/*w ww .j a v a2s.c o m*/ */ private void printUsage(final String commandLineSyntax, final Options options) { final PrintWriter writer = new PrintWriter(System.out); final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printUsage(writer, 80, commandLineSyntax, options); writer.flush(); }