List of usage examples for org.apache.commons.cli HelpFormatter printOptions
public void printOptions(PrintWriter pw, int width, Options options, int leftPad, int descPad)
Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.
From source file:co.cask.cdap.security.tools.AccessTokenClient.java
private void printOptions(boolean error) { PrintWriter pw = error ? new PrintWriter(System.err) : new PrintWriter(System.out); pw.println("Options:\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printOptions(pw, 100, options, 0, 10); pw.flush();/*from ww w .j a v a 2 s . com*/ pw.close(); if (error) { throw new UsageException(); } }
From source file:com.cloudera.sqoop.cli.ToolOptions.java
/** * Print the help to the specified PrintWriter, using the specified * help formatter.//from www. ja v a 2s. co m * @param formatter the HelpFormatter to use. * @param pw the PrintWriter to emit to. */ public void printHelp(HelpFormatter formatter, PrintWriter pw) { boolean first = true; for (RelatedOptions optGroup : optGroups) { if (!first) { pw.println(""); } pw.println(optGroup.getTitle() + ":"); formatter.printOptions(pw, formatter.getWidth(), optGroup, 0, 4); first = false; } }
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 w w .j a v a 2s . c o m*/ 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:com.emc.ecs.sync.cli.CliHelper.java
public static String longHelp() { StringWriter helpWriter = new StringWriter(); PrintWriter pw = new PrintWriter(helpWriter); HelpFormatter fmt = new HelpFormatter(); fmt.setWidth(79);/*from w ww .j ava 2s. com*/ // main CLI options Options options = ConfigUtil.wrapperFor(CliConfig.class).getOptions(); // sync options for (Option o : ConfigUtil.wrapperFor(SyncOptions.class).getOptions().getOptions()) { options.addOption(o); } // Make sure we do CommonOptions first String usage = "java -jar ecs-sync.jar -source <source-uri> [-filters <filter1>[,<filter2>,...]] -target <target-uri> [options]"; fmt.printHelp(pw, fmt.getWidth(), usage, "Common options:", options, fmt.getLeftPadding(), fmt.getDescPadding(), null); pw.print("\nAvailable plugins are listed below along with any custom options they may have\n"); // Do the rest for (ConfigWrapper<?> storageWrapper : ConfigUtil.allStorageConfigWrappers()) { pw.write('\n'); pw.write(String.format("%s (%s)\n", storageWrapper.getLabel(), storageWrapper.getUriPrefix())); fmt.printWrapped(pw, fmt.getWidth(), 4, " " + storageWrapper.getDocumentation()); fmt.printWrapped(pw, fmt.getWidth(), 4, " NOTE: Storage options must be prefixed by source- or target-, depending on which role they assume"); fmt.printOptions(pw, fmt.getWidth(), storageWrapper.getOptions(), fmt.getLeftPadding(), fmt.getDescPadding()); } for (ConfigWrapper<?> filterWrapper : ConfigUtil.allFilterConfigWrappers()) { pw.write('\n'); pw.write(String.format("%s (%s)\n", filterWrapper.getLabel(), filterWrapper.getCliName())); fmt.printWrapped(pw, fmt.getWidth(), 4, " " + filterWrapper.getDocumentation()); fmt.printOptions(pw, fmt.getWidth(), filterWrapper.getOptions(), fmt.getLeftPadding(), fmt.getDescPadding()); } return helpWriter.toString(); }
From source file:co.cask.cdap.gateway.tools.ClientToolBase.java
/** * Prints the usage message to the PrintStream indicated by the error parameter * * @param error Indicates which stream to print to. If true, throws UsageException. *///from w ww. ja va2s.c o m protected void printUsage(boolean error) { // print the positional args, if any, from child class printUsageTop(error); PrintWriter pw = error ? new PrintWriter(System.err) : new PrintWriter(System.out); pw.println("Options:\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printOptions(pw, 100, options, 0, 10); pw.flush(); pw.close(); if (error) { throw new UsageException(); } }
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 v a 2 s.co 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:com.technicolor.qeo.codegen.Main.java
private void usageExit(String message) { HelpFormatter hf = new HelpFormatter(); PrintWriter pw = null;/*from w ww . ja v a 2s .c om*/ if (null == message) { pw = new PrintWriter(System.out, true); } else { pw = new PrintWriter(System.err, true); pw.println("ERROR : " + message); pw.println(); } pw.println("Usage: qeo-codegen [options ...] [file ...]"); pw.println(); pw.println("Options:"); hf.printOptions(pw, 80, OPTIONS, 4, 2); System.exit(1); }
From source file:com.github.lindenb.jvarkit.util.command.Command.java
protected void printOptions(final PrintStream out) { final Options opts = new Options(); fillOptions(opts);//www. ja va2 s . c o m final HelpFormatter fmt = new HelpFormatter(); final PrintWriter w = new PrintWriter(out); fmt.setSyntaxPrefix(""); fmt.printOptions(w, 80, opts, 4, 5); w.flush(); }
From source file:com.aleerant.tnssync.PropertiesHandler.java
private void printUsageInfo() { final String header = "\n" + APP_NAME + " creates " + APP_TNSNAMES_FILENAME + " file for services listed in a config file (" + APP_TNSSYNC_FILENAME + ") getting Oracle Net Description data from a directory server (described in " + APP_LDAPORA_FILENAME + ").\n\n"; final String footer = "\n" + "Licensed under the Apache License Version 2.0, http://www.apache.org/licenses/LICENSE-2.0"; final String warning_msg = "WARNING: " + APP_NAME + " is able to owerwrite the existing " + APP_TNSNAMES_FILENAME + " file!\n\n"; final String logging_msg = APP_NAME + " provides logging functionality using Simple Logging Facade for Java (SLF4J) with a logback backend. " + "Logback looks for a configuration file named " + APP_TNSSYNC_LOGBACK_FILENAME + " in TNS_ADMIN directory.\n\n"; final int width = 120; final PrintWriter writer = new PrintWriter(System.out); HelpFormatter formatter = new HelpFormatter(); formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar [-ta <DIR>]"); formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar -h"); formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar -v"); formatter.printWrapped(writer, width, header); formatter.printWrapped(writer, width, warning_msg); formatter.printWrapped(writer, width, logging_msg); formatter.printOptions(writer, width, mOptions, 1, 3); formatter.printWrapped(writer, width, footer); writer.close();/*from w w w . ja va 2 s . c o m*/ }
From source file:co.cask.cdap.data2.transaction.TransactionManagerDebuggerMain.java
private void printUsage(boolean error) { PrintWriter pw;/* w w w . ja v a 2s . com*/ if (error) { pw = new PrintWriter(System.err); } else { pw = new PrintWriter(System.out); } pw.println("Usage:" + "\n\t " + TOOL_NAME + " view [ <option> ... ]" + "\n\t " + TOOL_NAME + " invalidate --host <name> --transaction <id>"); pw.println("\nOptions:\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printOptions(pw, 100, options, 0, 10); pw.flush(); pw.close(); }