Class HelpFormatter

java.lang.Object
com.aspectran.shell.command.option.HelpFormatter

public class HelpFormatter extends Object
A formatter of help messages for command line options.
  • Field Details

    • DEFAULT_WIDTH

      public static final int DEFAULT_WIDTH
      Default number of characters per line
      See Also:
    • DEFAULT_MAX_LEFT_WIDTH

      public static final int DEFAULT_MAX_LEFT_WIDTH
      Default number of characters per line
      See Also:
    • DEFAULT_LEFT_PAD

      public static final int DEFAULT_LEFT_PAD
      Default padding to the left of each line
      See Also:
    • DEFAULT_DESC_PAD

      public static final int DEFAULT_DESC_PAD
      number of space characters to be prefixed to each description line
      See Also:
    • OPTION_PREFIX

      public static final String OPTION_PREFIX
      Default prefix for shortOpts
      See Also:
    • LONG_OPTION_PREFIX

      public static final String LONG_OPTION_PREFIX
      Default prefix for long Option
      See Also:
  • Constructor Details

    • HelpFormatter

      public HelpFormatter(ShellConsole console)
      Creates a help formatter.
      Parameters:
      console - the console to which the help will be written
  • Method Details

    • getWidth

      public int getWidth()
    • setWidth

      public void setWidth(int width)
    • getMaxLeftWidth

      public int getMaxLeftWidth()
    • setMaxLeftWidth

      public void setMaxLeftWidth(int maxLeftWidth)
    • getLeftPad

      public int getLeftPad()
    • setLeftPad

      public void setLeftPad(int leftPad)
    • getDescPad

      public int getDescPad()
    • setDescPad

      public void setDescPad(int descPad)
    • getSyntaxPrefix

      public String getSyntaxPrefix()
    • setSyntaxPrefix

      public void setSyntaxPrefix(String prefix)
    • getArgName

      public String getArgName()
    • setArgName

      public void setArgName(String name)
    • getOptionComparator

      public Comparator<Option> getOptionComparator()
      Comparator used to sort the options when they output in help text. Defaults to case-insensitive alphabetical sorting by option key.
      Returns:
      the Comparator currently in use to sort the options
    • setOptionComparator

      public void setOptionComparator(Comparator<Option> comparator)
      Set the comparator used to sort the options when they output in help text. Passing in a null comparator will keep the options in the order they were declared.
      Parameters:
      comparator - the Comparator to use for sorting the options
    • printHelp

      public void printHelp(@NonNull Command command)
      Print the help with the given Command object.
      Parameters:
      command - the Command instance
    • printUsage

      public void printUsage(@NonNull String cmdLineSyntax)
      Print the help for options with the specified command line syntax.
      Parameters:
      cmdLineSyntax - the usage statement
    • printUsage

      public void printUsage(@NonNull Command command)
      Prints the usage statement for the specified command.
      Parameters:
      command - the Command instance
    • printOptions

      public int printOptions(@NonNull Options options)
      Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.
      Parameters:
      options - the Options instance
      Returns:
      the longest opt string's length
    • printArguments

      public void printArguments(@NonNull List<Arguments> argumentsList, int leftWidth)
    • printWrapped

      public void printWrapped(String text)
      Print the specified text to the specified PrintWriter.
      Parameters:
      text - the text to be written to the PrintWriter
    • renderWrappedText

      public static void renderWrappedText(StringBuilder sb, int width, int nextLineTabStop, String text)
      Render the specified text and return the rendered Options in a StringBuilder.
      Parameters:
      sb - the StringBuilder to place the rendered text into
      width - the number of characters to display per line
      nextLineTabStop - the position on the next line for the first tab
      text - the text to be rendered