io.vertx.core.cli

## Class UsageMessageFormatter

- java.lang.Object
- - io.vertx.core.cli.UsageMessageFormatter

- Direct Known Subclasses:
    io.vertx.core.impl.launcher.VertxCommandLauncher

      public class UsageMessageFormatter
      extends Object

  Usage message formatter.
  Author:
    Clement Escoffier

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_ARG_NAME` default name for an argument
    `static int` | `DEFAULT_DESC_PAD` number of space characters to be prefixed to each description line
    `static int` | `DEFAULT_LEFT_PAD` default padding to the left of each line
    `static String` | `DEFAULT_LONG_OPT_PREFIX` default prefix for long Option
    `static String` | `DEFAULT_LONG_OPT_SEPARATOR` default separator displayed between a long Option and its value
    `static String` | `DEFAULT_OPT_PREFIX` default prefix for shortOpts
    `static String` | `DEFAULT_USAGE_PREFIX` the string to display at the beginning of the usage statement
    `static int` | `DEFAULT_WIDTH` default number of characters per line
    `protected Comparator<Option>` | `optionComparator` Comparator used to sort the options when they output in help text Defaults to case-insensitive alphabetical sorting by option key.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UsageMessageFormatter()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `appendArgument(StringBuilder buff, Argument argument, boolean required)` Appends the usage clause for an Argument to a StringBuilder.
    `protected void` | `appendOption(StringBuilder buff, Option option)` Appends the usage clause for an Option to a StringBuilder.
    `void` | `buildWrapped(StringBuilder buffer, int nextLineTabStop, String text)` Builds the specified text to the specified buffer.
    `void` | `buildWrapped(StringBuilder buffer, String text)` Builds the specified text to the specified buffer.
    `void` | `computeOptionsAndArguments(StringBuilder buffer, List<Option> options, List<Argument> arguments)` Computes the help for the specified Options to the specified writer.
    `void` | `computeUsage(StringBuilder buffer, String cmdLineSyntax)`
    `void` | `computeUsageLine(StringBuilder buffer, String prefix, CLI cli)`
    `static String` | `createPadding(int len)` Return a String of padding of length `len`.
    `static int` | `findWrapPos(String text, int width, int startPos)` Finds the next text wrap position after `startPos` for the text in `text` with the column width `width`.
    `String` | `getArgName()`
    `int` | `getDescPadding()`
    `int` | `getLeftPadding()`
    `String` | `getLongOptionPrefix()`
    `String` | `getLongOptionSeparator()` Returns the separator displayed between a long option and its value.
    `String` | `getNewLine()`
    `Comparator<Option>` | `getOptionComparator()` Comparator used to sort the options when they output in help text.
    `String` | `getOptionPrefix()`
    `String` | `getUsagePrefix()`
    `int` | `getWidth()`
    `static boolean` | `isNullOrEmpty(String s)`
    `protected StringBuilder` | `renderCommands(StringBuilder sb, Collection<CLI> commands)`
    `protected StringBuilder` | `renderOptionsAndArguments(StringBuilder sb, List<Option> options, List<Argument> arguments)` Renders the specified Options and Arguments and return the rendered output in a StringBuilder.
    `protected StringBuilder` | `renderWrappedText(StringBuilder sb, int width, int nextLineTabStop, String text)` Render the specified text and return the rendered Options in a StringBuilder.
    `Appendable` | `renderWrappedTextBlock(StringBuilder sb, int width, int nextLineTabStop, String text)` Renders the specified text width a maximum width.
    `static String` | `rtrim(String s)` Remove the trailing whitespace from the specified String.
    `void` | `setArgName(String name)`
    `void` | `setDescPadding(int padding)`
    `void` | `setLeftPadding(int padding)`
    `void` | `setLongOptionPrefix(String prefix)`
    `void` | `setLongOptionSeparator(String longOptSeparator)` Set the separator displayed between a long option and its value.
    `void` | `setNewLine(String newline)`
    `void` | `setOptionComparator(Comparator<Option> comparator)` Set the comparator used to sort the options when they output in help text.
    `void` | `setOptionPrefix(String prefix)`
    `void` | `setUsagePrefix(String prefix)`
    `void` | `setWidth(int width)`
    `void` | `usage(StringBuilder builder, CLI cli)` Computes the usage of the given `CLI`.
    `void` | `usage(StringBuilder builder, String prefix, CLI cli)` Computes the usage of the given `CLI`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_WIDTH

          public static final int DEFAULT_WIDTH

      default number of characters per line
      See Also:
        Constant Field Values

    - #### DEFAULT_LEFT_PAD

          public static final int DEFAULT_LEFT_PAD

      default padding to the left of each line
      See Also:
        Constant Field Values

    - #### DEFAULT_DESC_PAD

          public static final int DEFAULT_DESC_PAD

      number of space characters to be prefixed to each description line
      See Also:
        Constant Field Values

    - #### DEFAULT_USAGE_PREFIX

          public static final String DEFAULT_USAGE_PREFIX

      the string to display at the beginning of the usage statement
      See Also:
        Constant Field Values

    - #### DEFAULT_OPT_PREFIX

          public static final String DEFAULT_OPT_PREFIX

      default prefix for shortOpts
      See Also:
        Constant Field Values

    - #### DEFAULT_LONG_OPT_PREFIX

          public static final String DEFAULT_LONG_OPT_PREFIX

      default prefix for long Option
      See Also:
        Constant Field Values

    - #### DEFAULT_LONG_OPT_SEPARATOR

          public static final String DEFAULT_LONG_OPT_SEPARATOR

      default separator displayed between a long Option and its value
      See Also:
        Constant Field Values

    - #### DEFAULT_ARG_NAME

          public static final String DEFAULT_ARG_NAME

      default name for an argument
      See Also:
        Constant Field Values

    - #### optionComparator

          protected Comparator<Option> optionComparator

      Comparator used to sort the options when they output in help text

      Defaults to case-insensitive alphabetical sorting by option key.

  - ### Constructor Detail

    - #### UsageMessageFormatter

          public UsageMessageFormatter()

  - ### Method Detail

    - #### setWidth

          public void setWidth(int width)

    - #### getWidth

          public int getWidth()

    - #### setLeftPadding

          public void setLeftPadding(int padding)

    - #### getLeftPadding

          public int getLeftPadding()

    - #### setDescPadding

          public void setDescPadding(int padding)

    - #### getDescPadding

          public int getDescPadding()

    - #### setUsagePrefix

          public void setUsagePrefix(String prefix)

    - #### getUsagePrefix

          public String getUsagePrefix()

    - #### setNewLine

          public void setNewLine(String newline)

    - #### getNewLine

          public String getNewLine()

    - #### setOptionPrefix

          public void setOptionPrefix(String prefix)

    - #### getOptionPrefix

          public String getOptionPrefix()

    - #### setLongOptionPrefix

          public void setLongOptionPrefix(String prefix)

    - #### getLongOptionPrefix

          public String getLongOptionPrefix()

    - #### setLongOptionSeparator

          public void setLongOptionSeparator(String longOptSeparator)

      Set the separator displayed between a long option and its value. Ensure that the separator specified is supported by the parser used, typically ' ' or '='.
      Parameters:
        `longOptSeparator` - the separator, typically ' ' or '='.

    - #### getLongOptionSeparator

          public String getLongOptionSeparator()

      Returns the separator displayed between a long option and its value.
      Returns:
        the separator

    - #### setArgName

          public void setArgName(String name)

    - #### getArgName

          public String getArgName()

    - #### 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

    - #### appendOption

          protected void appendOption(StringBuilder buff,
                                      Option option)

      Appends the usage clause for an Option to a StringBuilder.
      Parameters:
        `buff` - the StringBuilder to append to
        `option` - the Option to append

    - #### appendArgument

          protected void appendArgument(StringBuilder buff,
                                        Argument argument,
                                        boolean required)

      Appends the usage clause for an Argument to a StringBuilder.
      Parameters:
        `buff` - the StringBuilder to append to
        `argument` - the argument to add
        `required` - whether the Option is required or not

    - #### usage

          public void usage(StringBuilder builder,
                            CLI cli)

      Computes the usage of the given `CLI`.
      Parameters:
        `builder` - where the usage is going to be written
        `cli` - the cli

    - #### usage

          public void usage(StringBuilder builder,
                            String prefix,
                            CLI cli)

      Computes the usage of the given `CLI`.
      Parameters:
        `builder` - where the usage is going to be written
        `prefix` - a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name.
        `cli` - the cli

    - #### computeUsage

          public void computeUsage(StringBuilder buffer,
                                   String cmdLineSyntax)

    - #### computeUsageLine

          public void computeUsageLine(StringBuilder buffer,
                                       String prefix,
                                       CLI cli)

    - #### computeOptionsAndArguments

          public void computeOptionsAndArguments(StringBuilder buffer,
                                                 List<Option> options,
                                                 List<Argument> arguments)

      Computes the help for the specified Options to the specified writer.
      Parameters:
        `buffer` - The buffer to write the help to
        `options` - The command line Options
        `arguments` - the command line Arguments

    - #### buildWrapped

          public void buildWrapped(StringBuilder buffer,
                                   String text)

      Builds the specified text to the specified buffer.
      Parameters:
        `buffer` - The buffer to write the help to
        `text` - The text to be written to the buffer

    - #### buildWrapped

          public void buildWrapped(StringBuilder buffer,
                                   int nextLineTabStop,
                                   String text)

      Builds the specified text to the specified buffer.
      Parameters:
        `buffer` - The buffer to write the help to
        `nextLineTabStop` - The position on the next line for the first tab.
        `text` - The text to be written to the buffer

    - #### renderCommands

          protected StringBuilder renderCommands(StringBuilder sb,
                                                 Collection<CLI> commands)

    - #### isNullOrEmpty

          public static boolean isNullOrEmpty(String s)

    - #### renderOptionsAndArguments

          protected StringBuilder renderOptionsAndArguments(StringBuilder sb,
                                                            List<Option> options,
                                                            List<Argument> arguments)

      Renders the specified Options and Arguments and return the rendered output in a StringBuilder.
      Parameters:
        `sb` - The StringBuilder to place the rendered Options and Arguments into.
        `options` - The command line Options
        `arguments` - The command line Arguments
      Returns:
        the StringBuilder with the rendered content.

    - #### renderWrappedText

          protected StringBuilder 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.
      Returns:
        the StringBuilder with the rendered Options contents.

    - #### renderWrappedTextBlock

          public Appendable renderWrappedTextBlock(StringBuilder sb,
                                                   int width,
                                                   int nextLineTabStop,
                                                   String text)

      Renders the specified text width a maximum width. This method differs from renderWrappedText by not removing leading spaces after a new line.
      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.

    - #### findWrapPos

          public static int findWrapPos(String text,
                                        int width,
                                        int startPos)

      Finds the next text wrap position after `startPos` for the text in `text` with the column width `width`. The wrap point is the last position before startPos+width having a whitespace character (space, \n, \r). If there is no whitespace character before startPos+width, it will return startPos+width.
      Parameters:
        `text` - The text being searched for the wrap position
        `width` - width of the wrapped text
        `startPos` - position from which to start the lookup whitespace character
      Returns:
        position on which the text must be wrapped or -1 if the wrap position is at the end of the text

    - #### createPadding

          public static String createPadding(int len)

      Return a String of padding of length `len`.
      Parameters:
        `len` - The length of the String of padding to create.
      Returns:
        The String of padding

    - #### rtrim

          public static String rtrim(String s)

      Remove the trailing whitespace from the specified String.
      Parameters:
        `s` - The String to remove the trailing padding from.
      Returns:
        The String of without the trailing padding

Copyright © 2017. All rights reserved.