/** * Print the help for <code>options</code> with the specified * command line syntax. This method prints help information to * System.out. * * @param width the number of characters to be displayed on each line * @param cmdLineSyntax the syntax for this application * @param header the banner to display at the beginning of the help * @param options the Options instance * @param footer the banner to display at the end of the help * @param autoUsage whether to print an automatically generated * usage statement */ public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage) { PrintWriter pw = new PrintWriter(System.out); printHelp(pw, width, cmdLineSyntax, header, options, getLeftPadding(), getDescPadding(), footer, autoUsage); pw.flush(); }
private void dumpUsage(PrintStream output) { final String cmdName = "dumpapp"; HelpFormatter formatter = new HelpFormatter(); output.println("Usage: " + cmdName + " [options] <plugin> [plugin-options]"); PrintWriter writer = new PrintWriter(output); try { formatter.printOptions( writer, formatter.getWidth(), mGlobalOptions.options, formatter.getLeftPadding(), formatter.getDescPadding()); } finally { writer.flush(); } } }
@Override public void printUsage(String errorMessage) { output.println(); if (errorMessage != null) { output.println("ERROR: " + errorMessage); output.println(); } final PrintWriter printWriter = new PrintWriter(output); final int width = 80; final HelpFormatter hf = new HelpFormatter(); hf.setWidth(width); hf.printWrapped(printWriter, width, getDescription()); hf.printWrapped(printWriter, width, ""); if (isReferencable()) { hf.printWrapped(printWriter, width, "PRODUCES BACK-REFERENCES"); hf.printWrapped(printWriter, width, ""); } hf.printHelp(printWriter, hf.getWidth(), getName(), null, getOptions(), hf.getLeftPadding(), hf.getDescPadding(), null, false); printWriter.println(); printWriter.flush(); }
/** * Prints the info about a command to the given print writer. * * @param command command to print info * @param pw where to print the info */ public static void printCommandInfo(Command command, PrintWriter pw) { String description = String.format("%s: %s", command.getCommandName(), command.getDescription()); int width = 80; try { width = TerminalFactory.get().getWidth(); } catch (Exception e) { // In case the terminal factory failed to decide terminal type, use default width } HELP_FORMATTER.printWrapped(pw, width, description); HELP_FORMATTER.printUsage(pw, width, command.getUsage()); if (command.getOptions().getOptions().size() > 0) { HELP_FORMATTER.printOptions(pw, width, command.getOptions(), HELP_FORMATTER.getLeftPadding(), HELP_FORMATTER.getDescPadding()); } }
@Test public void testAccessors() { HelpFormatter formatter = new HelpFormatter(); formatter.setArgName("argname"); assertEquals("arg name", "argname", formatter.getArgName()); formatter.setDescPadding(3); assertEquals("desc padding", 3, formatter.getDescPadding()); formatter.setLeftPadding(7); assertEquals("left padding", 7, formatter.getLeftPadding()); formatter.setLongOptPrefix("~~"); assertEquals("long opt prefix", "~~", formatter.getLongOptPrefix()); formatter.setNewLine("\n"); assertEquals("new line", "\n", formatter.getNewLine()); formatter.setOptPrefix("~"); assertEquals("opt prefix", "~", formatter.getOptPrefix()); formatter.setSyntaxPrefix("-> "); assertEquals("syntax prefix", "-> ", formatter.getSyntaxPrefix()); formatter.setWidth(80); assertEquals("width", 80, formatter.getWidth()); }
private static void printHelpMessage(MigrationOptions options){ HelpFormatter helpFormatter = new HelpFormatter(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out, Charset.defaultCharset()); PrintWriter printWriter = new PrintWriter(new BufferedWriter(outputStreamWriter)); int width = helpFormatter.getWidth(); int leftPadding = helpFormatter.getLeftPadding(); int descPadding = helpFormatter.getDescPadding(); helpFormatter.printHelp(printWriter, width, "graql migrate", null, options.getOptions(), leftPadding, descPadding, null); printWriter.flush(); }
public static void printHelp(PrintStream stream, String app) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(new PrintWriter(stream, true), formatter.getWidth(), app, HELP_HEADER, OPTIONS, formatter.getLeftPadding(), formatter.getDescPadding(), HELP_FOOTER, true); }
/** * Print the help for <code>options</code> with the specified * command line syntax. This method prints help information to * System.out. * * @param width the number of characters to be displayed on each line * @param cmdLineSyntax the syntax for this application * @param header the banner to display at the beginning of the help * @param options the Options instance * @param footer the banner to display at the end of the help * @param autoUsage whether to print an automatically generated * usage statement */ public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage) { PrintWriter pw = new PrintWriter(System.out); printHelp(pw, width, cmdLineSyntax, header, options, getLeftPadding(), getDescPadding(), footer, autoUsage); pw.flush(); }
/** * Returns a help message, including the program usage and information about the arguments registered with the ArgumentParser. * * @return the usage information about the arguments registered with the ArgumentParser. */ public String getUsageInformation() { HelpFormatter formatter = new HelpFormatter(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); formatter.printHelp(pw, formatter.getWidth(), applicationName, null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null, false); pw.flush(); return sw.toString(); }
/** * Returns a help message, including the program usage and information about the arguments registered with the ArgumentParser. * * @return the usage information about the arguments registered with the ArgumentParser. */ public String getUsageInformation() { HelpFormatter formatter = new HelpFormatter(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); formatter.printHelp(pw, formatter.getWidth(), applicationName, null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null, false); pw.flush(); return sw.toString(); }
private static void usage() { PrintWriter out = new PrintWriter(System.err); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(out, formatter.getWidth(), "glacier " + "upload vault_name file1 file2 ... | " + "delete vault_name archiveId | " + "download vault_name archiveId output_file | " + "create-vault vault_name | " + "delete-vault vault_name | " + "inventory vault_name | " + "list vault_name | " + "info vault_name", null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null); out.flush(); System.exit(1); }
public static void printCommandUsage(String name, Options options, String usageFooter, PrintStream err) { HelpFormatter formatter = new HelpFormatter(); PrintWriter writer = new PrintWriter(err); formatter.printUsage(writer, 80, TOOL_NAME + " [OPTIONS] " + name, getOptionsWithHelp(options)); formatter.printWrapped(writer, 80, System.lineSeparator() + "Available options are:" + System.lineSeparator()); formatter.printOptions(writer, 80, getScriptOptions(), formatter.getLeftPadding(), formatter.getDescPadding()); formatter.printWrapped(writer, 80, System.lineSeparator() + "Available arguments are:" + System.lineSeparator()); formatter.printOptions(writer, 80, getOptionsWithHelp(options), formatter.getLeftPadding(), formatter.getDescPadding()); formatter.printWrapped(writer, 80, System.lineSeparator() + Objects.toString(usageFooter, "")); writer.flush(); }
private int printUsage(PrintStream err) { HelpFormatter formatter = new HelpFormatter(); PrintWriter usage = new PrintWriter(err); formatter.printUsage(usage, 80, "itools [OPTIONS] COMMAND [ARGS]"); usage.append(System.lineSeparator()) .append("Available options are:") .append(System.lineSeparator()); formatter.printOptions(usage, 80, getScriptOptions(), formatter.getLeftPadding(), formatter.getDescPadding()); usage.append(System.lineSeparator()) .append("Available commands are:") .append(System.lineSeparator()) .append(System.lineSeparator()); List<Tool> allTools = Lists.newArrayList(tools).stream() .filter(t -> !t.getCommand().isHidden()).collect(Collectors.toList()); // group commands by theme Map<String, Collection<Tool>> toolsByTheme = new TreeMap<>(Multimaps.index(allTools, tool -> tool.getCommand().getTheme()).asMap()); for (Map.Entry<String, Collection<Tool>> entry : toolsByTheme.entrySet()) { String theme = entry.getKey(); usage.append(theme != null ? theme : "Others").append(":").append(System.lineSeparator()); entry.getValue().stream() .sorted(Comparator.comparing(t -> t.getCommand().getName())) .forEach(tool -> usage.append(String.format(" %-40s %s", tool.getCommand().getName(), tool.getCommand().getDescription())).append(System.lineSeparator()) ); usage.append(System.lineSeparator()); } usage.flush(); return COMMAND_NOT_FOUND_STATUS; }
PrintWriter printWriter = new PrintWriter(System.out); int width = helpFormatter.getWidth(); int leftPadding = helpFormatter.getLeftPadding(); int descPadding = helpFormatter.getDescPadding(); helpFormatter.printHelp(printWriter, width, "graql.sh", null, options, leftPadding, descPadding, null);
hf.printHelp(pw, hf.getWidth(), "[options] [torrent [torrent ...]]", null, options, hf.getLeftPadding(), hf.getDescPadding(), null, false); pw.flush(); } catch (Exception e) {
void processArgs(String[] args, Reader source, PrintStream target) { try { CLIConfig cliConfig = parse(args); try (BufferedReader reader = new BufferedReader(source)) { Parser parser = parseInput(cliConfig, reader); String format = cliConfig.getFormat().toString(); switch (format.toUpperCase()) { case "JSON": printToJSON(parser, target); break; case "CSV": printToCSV(parser, target); break; } } } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); PrintWriter pw = new PrintWriter(target); formatter.printHelp(pw, formatter.getWidth(), "utah", "", buildOptions(), formatter.getLeftPadding(), formatter.getDescPadding(), "", true); pw.flush(); } }
fmt.printHelp(pw, fmt.getWidth(), usage, "Common options:", options, fmt.getLeftPadding(), fmt.getDescPadding(), null); 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()); 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());