Class DefaultUsageFormatter

    • Constructor Detail

      • DefaultUsageFormatter

        public DefaultUsageFormatter​(JCommander commander)
    • Method Detail

      • usage

        public final void usage​(String commandName,
                                StringBuilder out)
        Store the usage for the argument command in the argument string builder.
        Specified by:
        usage in interface IUsageFormatter
      • usage

        public final void usage​(String commandName,
                                StringBuilder out,
                                String indent)
        Store the usage for the command in the argument string builder, indenting every line with the value of indent.
        Specified by:
        usage in interface IUsageFormatter
      • appendMainLine

        public void appendMainLine​(StringBuilder out,
                                   boolean hasOptions,
                                   boolean hasCommands,
                                   int indentCount,
                                   String indent)
        Appends the main line segment of the usage to the argument string builder, indenting every line with indentCount-many indent.
        Parameters:
        out - the builder to append to
        hasOptions - if the options section should be appended
        hasCommands - if the comments section should be appended
        indentCount - the amount of indentation to apply
        indent - the indentation
      • appendAllParametersDetails

        public void appendAllParametersDetails​(StringBuilder out,
                                               int indentCount,
                                               String indent,
                                               List<ParameterDescription> sortedParameters)
        Appends the details of all parameters in the given order to the argument string builder, indenting every line with indentCount-many indent.
        Parameters:
        out - the builder to append to
        indentCount - the amount of indentation to apply
        indent - the indentation
        sortedParameters - the parameters to append to the builder
      • appendCommands

        public void appendCommands​(StringBuilder out,
                                   int indentCount,
                                   int descriptionIndent,
                                   String indent)
        Appends the details of all commands to the argument string builder, indenting every line with indentCount-many indent. The commands are obtained from calling JCommander.getRawCommands() and the commands are resolved using JCommander.findCommandByAlias(String) on the underlying commander instance.
        Parameters:
        out - the builder to append to
        indentCount - the amount of indentation to apply
        descriptionIndent - the indentation for the description
        indent - the indentation
      • wrapDescription

        public void wrapDescription​(StringBuilder out,
                                    int indent,
                                    int currentLineIndent,
                                    String description)
        Wrap a potentially long line to the value obtained by calling JCommander.getColumnSize() on the underlying commander instance.
        Parameters:
        out - the output
        indent - the indentation in spaces for lines after the first line.
        currentLineIndent - the length of the indentation of the initial line
        description - the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.
      • wrapDescription

        public void wrapDescription​(StringBuilder out,
                                    int indent,
                                    String description)
        Wrap a potentially long line to { @link #commander#getColumnSize()}.
        Parameters:
        out - the output
        indent - the indentation in spaces for lines after the first line.
        description - the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.
        See Also:
        wrapDescription(StringBuilder, int, int, String)
      • getI18nString

        public static String getI18nString​(ResourceBundle bundle,
                                           String key,
                                           String def)
        Returns the internationalized version of the string if available, otherwise it returns def.
        Returns:
        the internationalized version of the string if available, otherwise it returns def
      • s

        public static String s​(int count)
        Returns count-many spaces.
        Returns:
        count-many spaces