/** Returns command footer text as a string. Footer text can be zero or more lines, and can be specified * declaratively with the {@link Command#footer()} annotation attribute or programmatically by * setting the Help instance's {@link Help#footer} field. * @param params Arguments referenced by the format specifiers in the footer strings * @return the footer lines combined into a single String (which may be empty) */ public String footer(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().footer(), new StringBuilder(), params).toString(); }
/** Returns command custom synopsis as a string. A custom synopsis can be zero or more lines, and can be * specified declaratively with the {@link Command#customSynopsis()} annotation attribute or programmatically * by setting the Help instance's {@link Help#customSynopsis} field. * @param params Arguments referenced by the format specifiers in the synopsis strings * @return the custom synopsis lines combined into a single String (which may be empty) */ public String customSynopsis(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().customSynopsis(), new StringBuilder(), params).toString(); } /** Returns command description text as a string. Description text can be zero or more lines, and can be specified
/** Returns the command header text as a string. Header text can be zero or more lines, and can be specified * declaratively with the {@link Command#header()} annotation attribute or programmatically by * setting the Help instance's {@link Help#header} field. * @param params Arguments referenced by the format specifiers in the header strings * @return the header lines combined into a single String (which may be empty) */ public String header(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().header(), new StringBuilder(), params).toString(); } /** Returns command footer text as a string. Footer text can be zero or more lines, and can be specified
/** Returns the text displayed before the footer text; the result of {@code String.format(footerHeading, params)}. * @param params the parameters to use to format the footer heading * @return the formatted footer heading */ public String footerHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().footerHeading(), params); } /** Returns a 2-column list with command names and the first line of their header or (if absent) description.
/** Returns the command header text as a string. Header text can be zero or more lines, and can be specified * declaratively with the {@link Command#header()} annotation attribute or programmatically by * setting the Help instance's {@link Help#header} field. * @param params Arguments referenced by the format specifiers in the header strings * @return the header lines combined into a single String (which may be empty) */ public String header(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().header(), new StringBuilder(), params).toString(); } /** Returns command footer text as a string. Footer text can be zero or more lines, and can be specified
/** Returns the text displayed before the description text; an empty string if there is no description, * otherwise the result of {@code String.format(descriptionHeading, params)}. * @param params the parameters to use to format the description heading * @return the formatted description heading */ public String descriptionHeading(Object... params) { return empty(commandSpec.usageMessage().descriptionHeading()) ? "" : heading(ansi(), width(), commandSpec.usageMessage().descriptionHeading(), params); }
/** Returns the text displayed before the synopsis text; the result of {@code String.format(synopsisHeading, params)}. * @param params the parameters to use to format the synopsis heading * @return the formatted synopsis heading */ public String synopsisHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().synopsisHeading(), params); }
/** Returns command footer text as a string. Footer text can be zero or more lines, and can be specified * declaratively with the {@link Command#footer()} annotation attribute or programmatically by * setting the Help instance's {@link Help#footer} field. * @param params Arguments referenced by the format specifiers in the footer strings * @return the footer lines combined into a single String (which may be empty) */ public String footer(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().footer(), new StringBuilder(), params).toString(); }
/** Returns command custom synopsis as a string. A custom synopsis can be zero or more lines, and can be * specified declaratively with the {@link Command#customSynopsis()} annotation attribute or programmatically * by setting the Help instance's {@link Help#customSynopsis} field. * @param params Arguments referenced by the format specifiers in the synopsis strings * @return the custom synopsis lines combined into a single String (which may be empty) */ public String customSynopsis(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().customSynopsis(), new StringBuilder(), params).toString(); } /** Returns command description text as a string. Description text can be zero or more lines, and can be specified
/** Returns a 2-column list with command names and the first line of their header or (if absent) description. * @return a usage help section describing the added commands */ public String commandList() { if (subcommands().isEmpty()) { return ""; } int commandLength = maxLength(subcommands().keySet()); Help.TextTable textTable = Help.TextTable.forColumns(ansi(), new Help.Column(commandLength + 2, 2, Help.Column.Overflow.SPAN), new Help.Column(width() - (commandLength + 2), 2, Help.Column.Overflow.WRAP)); for (Map.Entry<String, Help> entry : subcommands().entrySet()) { Help help = entry.getValue(); UsageMessageSpec usage = help.commandSpec().usageMessage(); String header = !empty(usage.header()) ? usage.header()[0] : (!empty(usage.description()) ? usage.description()[0] : ""); Text[] lines = ansi().text(format(header)).splitLines(); for (int i = 0; i < lines.length; i++) { textTable.addRowValues(i == 0 ? help.commandNamesText(", ") : Ansi.EMPTY_TEXT, lines[i]); } } return textTable.toString(); } private static int maxLength(Collection<String> any) {
/** * Returns the detailed synopsis text by inserting the command name before the specified text with options and positional parameters details. * @param synopsisHeadingLength length of the synopsis heading string to be displayed on the same line as the first synopsis line. * For example, if the synopsis heading is {@code "Usage: "}, this value is 7. * @param optionsAndPositionalsAndCommandsDetails formatted string with options, positional parameters and subcommands. * Follows the unix convention of showing optional options and parameters in square brackets ({@code [ ]}). * @return the detailed synopsis text, in multiple lines if the length exceeds the usage width */ protected String insertSynopsisCommandName(int synopsisHeadingLength, Text optionsAndPositionalsAndCommandsDetails) { // Fix for #142: first line of synopsis overshoots max. characters String commandName = commandSpec.qualifiedName(); int firstColumnLength = commandName.length() + synopsisHeadingLength; // synopsis heading ("Usage: ") may be on the same line, so adjust column width TextTable textTable = TextTable.forColumnWidths(ansi(), firstColumnLength, width() - firstColumnLength); textTable.indentWrappedLines = 1; // don't worry about first line: options (2nd column) always start with a space // right-adjust the command name by length of synopsis heading Text PADDING = Ansi.OFF.new Text(stringOf('X', synopsisHeadingLength)); textTable.addRowValues(PADDING.concat(colorScheme.commandText(commandName)), optionsAndPositionalsAndCommandsDetails); return textTable.toString().substring(synopsisHeadingLength); // cut off leading synopsis heading spaces }
private Layout createLayout(int longOptionsColumnWidth) { return new Layout(colorScheme, TextTable.forDefaultColumns(colorScheme.ansi(), longOptionsColumnWidth, width()), createDefaultOptionRenderer(), createDefaultParameterRenderer()); }
/** Returns the text displayed before the description text; an empty string if there is no description, * otherwise the result of {@code String.format(descriptionHeading, params)}. * @param params the parameters to use to format the description heading * @return the formatted description heading */ public String descriptionHeading(Object... params) { return empty(commandSpec.usageMessage().descriptionHeading()) ? "" : heading(ansi(), width(), commandSpec.usageMessage().descriptionHeading(), params); }
/** Returns the text displayed before the header text; the result of {@code String.format(headerHeading, params)}. * @param params the parameters to use to format the header heading * @return the formatted header heading */ public String headerHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().headerHeading(), params); }
/** Returns command description text as a string. Description text can be zero or more lines, and can be specified * declaratively with the {@link Command#description()} annotation attribute or programmatically by * setting the Help instance's {@link Help#description} field. * @param params Arguments referenced by the format specifiers in the description strings * @return the description lines combined into a single String (which may be empty) */ public String description(Object... params) { return join(ansi(), width(), commandSpec.usageMessage().description(), new StringBuilder(), params).toString(); } /** Returns the command header text as a string. Header text can be zero or more lines, and can be specified
/** Returns the text displayed before the footer text; the result of {@code String.format(footerHeading, params)}. * @param params the parameters to use to format the footer heading * @return the formatted footer heading */ public String footerHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().footerHeading(), params); } /** Returns a 2-column list with command names and the first line of their header or (if absent) description.
/** Returns the text displayed before the option list; an empty string if there are no options, * otherwise the result of {@code String.format(optionListHeading, params)}. * @param params the parameters to use to format the option list heading * @return the formatted option list heading */ public String optionListHeading(Object... params) { return commandSpec.optionsMap().isEmpty() ? "" : heading(ansi(), width(), commandSpec.usageMessage().optionListHeading(), params); }
/** Returns the text displayed before the command list; an empty string if there are no commands, * otherwise the result of {@code String.format(commandListHeading, params)}. * @param params the parameters to use to format the command list heading * @return the formatted command list heading */ public String commandListHeading(Object... params) { return commands.isEmpty() ? "" : heading(ansi(), width(), commandSpec.usageMessage().commandListHeading(), params); }
/** Returns the text displayed before the positional parameter list; an empty string if there are no positional * parameters, otherwise the result of {@code String.format(parameterListHeading, params)}. * @param params the parameters to use to format the parameter list heading * @return the formatted parameter list heading */ public String parameterListHeading(Object... params) { return commandSpec.positionalParameters().isEmpty() ? "" : heading(ansi(), width(), commandSpec.usageMessage().parameterListHeading(), params); }
/** Returns the text displayed before the synopsis text; the result of {@code String.format(synopsisHeading, params)}. * @param params the parameters to use to format the synopsis heading * @return the formatted synopsis heading */ public String synopsisHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().synopsisHeading(), params); }