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:io.werval.cli.DamnSmallDevShell.java
private static void printHelp(Options options, PrintWriter out) { HelpFormatter help = new HelpFormatter(); help.setOptionComparator(new OptionsComparator()); help.printUsage(out, WIDTH, "io.werval.cli [options] [command(s)]"); out.print("\n" + " The Damn Small Werval DevShell\n" + " - do not manage dependencies ;\n" + " - do not allow you to extend the build ;\n" + " - do not assemble applications.\n"); help.printWrapped(out, WIDTH, 2,//from w w w . jav a 2 s. c o m "\n" + "Meaning you have to manage your application dependencies and assembly yourself. " + "Theses limitations make this DevShell suitable for quick prototyping only. " + "Prefer the Gradle or Maven build systems integration."); out.println("\n io.werval.cli is part of the Werval Development Kit - http://werval.io"); out.println("\n" + "Commands:\n\n" + " new <appdir> Create a new skeleton application in the 'appdir' directory.\n" + " secret Generate a new application secret.\n" + " clean Delete devshell temporary directory, see 'tmpdir' option.\n" + " devshell Run the Application in development mode.\n" + " start Run the Application in production mode.\n" + "\n" + " If no command is specified, 'start' is assumed."); out.println("\n" + "Options:" + "\n"); help.printOptions(out, WIDTH, options, 2, 2); help.printWrapped(out, WIDTH, 2, "\n" + "All paths are relative to the current working directory, " + "except if they are absolute of course."); help.printWrapped(out, WIDTH, 2, "\n" + "Licensed under the Apache License Version 2.0, http://www.apache.org/licenses/LICENSE-2.0"); out.println(); }
From source file:com.github.lindenb.mscheduler.MScheduler.java
private int printHelp(final String helpName) { final HelpFormatter fmt = new HelpFormatter(); final PrintWriter pw = new PrintWriter(System.out); pw.println(helpName);//from w w w . j a v a2 s.com fmt.printOptions(pw, 80, this.options, 5, 5); pw.println(); pw.flush(); pw.close(); return 0; }
From source file:com.datatorrent.stram.cli.DTCli.java
private void printHelp(String command, CommandSpec commandSpec, PrintStream os) { if (consolePresent) { os.print("\033[0;93m"); os.print(command);// w w w. j ava 2 s. c o m os.print("\033[0m"); } else { os.print(command); } if (commandSpec instanceof OptionsCommandSpec) { OptionsCommandSpec ocs = (OptionsCommandSpec) commandSpec; if (ocs.options != null) { os.print(" [options]"); } } if (commandSpec.requiredArgs != null) { for (Arg arg : commandSpec.requiredArgs) { if (consolePresent) { os.print(" \033[3m" + arg + "\033[0m"); } else { os.print(" <" + arg + ">"); } } } if (commandSpec.optionalArgs != null) { for (Arg arg : commandSpec.optionalArgs) { if (consolePresent) { os.print(" [\033[3m" + arg + "\033[0m"); } else { os.print(" [<" + arg + ">"); } if (arg instanceof VarArg) { os.print(" ..."); } os.print("]"); } } os.println("\n\t" + commandSpec.description); if (commandSpec instanceof OptionsCommandSpec) { OptionsCommandSpec ocs = (OptionsCommandSpec) commandSpec; if (ocs.options != null) { os.println("\tOptions:"); HelpFormatter formatter = new HelpFormatter(); PrintWriter pw = new PrintWriter(os); formatter.printOptions(pw, 80, ocs.options, 12, 4); pw.flush(); } } }
From source file:com.datatorrent.stram.cli.ApexCli.java
private void printHelp(String command, CommandSpec commandSpec, PrintStream os) { if (consolePresent) { os.print(getHighlightColor());/* w ww . j a v a2 s . co m*/ os.print(command); os.print(COLOR_RESET); } else { os.print(command); } if (commandSpec instanceof OptionsCommandSpec) { OptionsCommandSpec ocs = (OptionsCommandSpec) commandSpec; if (ocs.options != null) { os.print(" [options]"); } } if (commandSpec.requiredArgs != null) { for (Arg arg : commandSpec.requiredArgs) { if (consolePresent) { os.print(" " + ITALICS + arg + COLOR_RESET); } else { os.print(" <" + arg + ">"); } } } if (commandSpec.optionalArgs != null) { for (Arg arg : commandSpec.optionalArgs) { if (consolePresent) { os.print(" [" + ITALICS + arg + COLOR_RESET); } else { os.print(" [<" + arg + ">"); } if (arg instanceof VarArg) { os.print(" ..."); } os.print("]"); } } os.println("\n\t" + commandSpec.description); if (commandSpec instanceof OptionsCommandSpec) { OptionsCommandSpec ocs = (OptionsCommandSpec) commandSpec; if (ocs.options != null) { os.println("\tOptions:"); HelpFormatter formatter = new HelpFormatter(); PrintWriter pw = new PrintWriter(os); formatter.printOptions(pw, 80, ocs.options, 12, 4); pw.flush(); } } }
From source file:openlr.otk.options.UsageBuilder.java
/** * Prints the command line syntax.//w ww. java 2s .c o m * * @param target * The target stream to write to * @param options * The tool options * @param argsList * The tool arguments * @param toolID * The tool short name * @param toolDescription * The description of the tool */ public static void usage(final OutputStream target, final Options options, final List<Argument<?>> argsList, final String toolID, final String toolDescription) { HelpFormatter formatter = new HelpFormatter(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(target, IOUtils.SYSTEM_DEFAULT_CHARSET)); String optionsListStr = buildOptionsList(options); String argsListStr = buildArgumentsList(argsList); formatter.printUsage(pw, HelpFormatter.DEFAULT_WIDTH, "java -jar otk-<version>.jar " + toolID + " " + optionsListStr + " " + argsListStr); formatter.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, toolDescription); if (options.getOptions().size() > 0) { formatter.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD); } printArgumentDescriptions(pw, argsList); formatter.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, USAGE_FOOTER); pw.flush(); }
From source file:openlr.otk.options.UsageBuilder.java
/** * Prints the help for the tool arguments. * /*from w w w . ja va 2s . c o m*/ * @param pw * The writer to use * @param args * The tool arguments */ private static void printArgumentDescriptions(final PrintWriter pw, final List<Argument<?>> args) { if (args.size() > 0) { pw.write(IOUtils.LINE_SEPARATOR); // We use the HelpFormatter to format the argument help for us // by providing fake options containing the arguments Options options = new Options(); for (Argument<?> argument : args) { Option opt = new Option(null, argument.getName(), false, argument.getDescription()); options.addOption(opt); } HelpFormatter formatter = new HelpFormatter(); formatter.setLongOptPrefix(""); formatter.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD); } }
From source file:org.apache.falcon.cli.CLIParser.java
/** * Print the help for the parser to standard output. *//*from ww w . j av a2 s . c o m*/ public void showHelp() { PrintWriter pw = new PrintWriter(System.out); pw.println("usage: "); for (String s : cliHelp) { pw.println(LEFT_PADDING + s); } pw.println(); HelpFormatter formatter = new HelpFormatter(); for (Map.Entry<String, Options> entry : commands.entrySet()) { String s = LEFT_PADDING + cliName + " " + entry.getKey() + " "; if (entry.getValue().getOptions().size() > 0) { pw.println(s + "<OPTIONS> " + commandsHelp.get(entry.getKey())); formatter.printOptions(pw, 100, entry.getValue(), s.length(), 3); } else { pw.println(s + commandsHelp.get(entry.getKey())); } pw.println(); } pw.flush(); }
From source file:org.apache.oozie.cli.CLIParser.java
/** * Print the help for the parser to standard output. * //from ww w .ja va 2s . c o m * @param commandLine the command line */ public void showHelp(CommandLine commandLine) { PrintWriter pw = new PrintWriter(System.out); pw.println("usage: "); for (String s : cliHelp) { pw.println(LEFT_PADDING + s); } pw.println(); HelpFormatter formatter = new HelpFormatter(); Set<String> commandsToPrint = commands.keySet(); String[] args = commandLine.getArgs(); if (args.length > 0 && commandsToPrint.contains(args[0])) { commandsToPrint = new HashSet<String>(); commandsToPrint.add(args[0]); } for (String comm : commandsToPrint) { Options opts = commands.get(comm); String s = LEFT_PADDING + cliName + " " + comm + " "; if (opts.getOptions().size() > 0) { pw.println(s + "<OPTIONS> " + commandsHelp.get(comm)); formatter.printOptions(pw, 100, opts, s.length(), 3); } else { pw.println(s + commandsHelp.get(comm)); } pw.println(); } pw.flush(); }
From source file:org.apache.openejb.cli.MainImpl.java
private static void help(final boolean printHeader) { // Here we are using commons-cli to create the list of available commands // We actually use a different Options object to parse the 'openejb' command try {//from www . j a v a 2 s . co m final Options options = new Options(); final ResourceFinder commandFinder = new ResourceFinder("META-INF"); final Map<String, Properties> commands = commandFinder.mapAvailableProperties("org.apache.openejb.cli"); for (final Map.Entry<String, Properties> command : commands.entrySet()) { if (command.getKey().contains(".")) { continue; } final Properties p = command.getValue(); final String description = p.getProperty(descriptionI18n, p.getProperty(descriptionBase)); options.addOption(command.getKey(), false, description); } final HelpFormatter formatter = new HelpFormatter(); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); final String syntax = "openejb <command> [options] [args]"; final String header = "\nAvailable commands:"; final String footer = "\n" + "Try 'openejb <command> --help' for help on a specific command.\n" + "For example 'openejb deploy --help'.\n" + "\n" + "Apache OpenEJB -- EJB Container System and Server.\n" + "For additional information, see http://tomee.apache.org\n" + "Bug Reports to <users@tomee.apache.org>"; if (!printHeader) { pw.append(header).append("\n\n"); formatter.printOptions(pw, 74, options, 1, 3); } else { formatter.printHelp(pw, 74, syntax, header, options, 1, 3, footer, false); } pw.flush(); // Fix up the commons-cli output to our liking. String text = sw.toString().replaceAll("\n -", "\n "); text = text.replace("\nApache OpenEJB", "\n\nApache OpenEJB"); System.out.print(text); } catch (final IOException e) { e.printStackTrace(); } }
From source file:org.apache.parquet.tools.Main.java
public static void showUsage(HelpFormatter format, PrintWriter err, String name, Command command) { Options options = mergeOptions(OPTIONS, command.getOptions()); String[] usage = command.getUsageDescription(); String ustr = name + " [option...]"; if (usage != null && usage.length >= 1) { ustr = ustr + " " + usage[0]; }/*from w ww . j a va2 s.c o m*/ format.printWrapped(err, WIDTH, name + ":\n" + command.getCommandDescription()); format.printUsage(err, WIDTH, ustr); format.printWrapped(err, WIDTH, LEFT_PAD, "where option is one of:"); format.printOptions(err, WIDTH, options, LEFT_PAD, DESC_PAD); if (usage != null && usage.length >= 2) { for (int i = 1; i < usage.length; ++i) { format.printWrapped(err, WIDTH, LEFT_PAD, usage[i]); } } }