Class OptionFormatter.Builder

java.lang.Object
org.apache.commons.cli.help.OptionFormatter.Builder
All Implemented Interfaces:
Supplier<OptionFormatter>
Enclosing class:
OptionFormatter

public static final class OptionFormatter.Builder extends Object implements Supplier<OptionFormatter>
Builds instances of OptionFormatter.
  • Field Details

    • argNameDelimiters

      private final String[] argNameDelimiters
      The argument name delimiters
    • defaultArgName

      private String defaultArgName
      The default argument name
    • deprecatedFormatFunction

      private Function<Option,String> deprecatedFormatFunction
      The function to create the deprecated message for an option
    • longOptPrefix

      private String longOptPrefix
      The long option prefix
    • optPrefix

      private String optPrefix
      The option prefix
    • optSeparator

      private String optSeparator
      The separator between long and short options
    • optArgSeparator

      private String optArgSeparator
      The separator between the opt and/or longOpt and the argument name
    • optionalDelimiters

      private final String[] optionalDelimiters
      The delimiters surrounding optional Option instances.
    • syntaxFormatFunction

      private BiFunction<OptionFormatter,Boolean,String> syntaxFormatFunction
      A function to convert the OptionFormatter into an entry in the syntax description.
  • Constructor Details

    • Builder

      private Builder()
      Default constructor. Uses the defaults specified in OptionFormatter.
    • Builder

      public Builder(OptionFormatter optionFormatter)
      Constructor that takes the arguments from the supplied OptionFormatter
      Parameters:
      optionFormatter - The option formatter to provide values for the builder.
  • Method Details

    • build

      public OptionFormatter build(Option option)
      Build an OptionFormatter to format the specified option.
      Parameters:
      option - The Option to format.
      Returns:
      An OptionFormatter to format the specified option.
    • get

      public OptionFormatter get()
      Specified by:
      get in interface Supplier<OptionFormatter>
    • setArgumentNameDelimiters

      public OptionFormatter.Builder setArgumentNameDelimiters(String begin, String end)
      Specifies the starting and ending argument name delimiters for Option instances.
      Parameters:
      begin - the beginning delimiter.
      end - the ending delimiter.
      Returns:
      this instance.
    • setDefaultArgName

      public OptionFormatter.Builder setDefaultArgName(String name)
      Sets the default argument name.
      Parameters:
      name - the new value of default argument name.
      Returns:
      this
    • setDeprecatedFormatFunction

      public OptionFormatter.Builder setDeprecatedFormatFunction(Function<Option,String> deprecatedFormatFunction)
      Specifies the function to construct the deprecated massage for the Option. Should include the description text if desired.
      Parameters:
      deprecatedFormatFunction - the function to specify the deprecated message for the option.
      Returns:
      this instance.
    • setLongOptPrefix

      public OptionFormatter.Builder setLongOptPrefix(String prefix)
      Sets the long option prefix.
      Parameters:
      prefix - prefix for long options.
      Returns:
      this
    • setOptArgSeparator

      public OptionFormatter.Builder setOptArgSeparator(String optArgSeparator)
      Sets the separator displayed between a options and the argument name. Typically ' ' or '='.
      Parameters:
      optArgSeparator - the separator.
      Returns:
      this
      Since:
      1.3
    • setOptionalDelimiters

      public OptionFormatter.Builder setOptionalDelimiters(String begin, String end)
      Specifies the starting and ending delimiters for optional Option instances.
      Parameters:
      begin - the beginning delimiter.
      end - the ending delimiter.
      Returns:
      this instance.
    • setOptPrefix

      public OptionFormatter.Builder setOptPrefix(String optPrefix)
      Specifies the short option prefix.
      Parameters:
      optPrefix - the prefix for short options.
      Returns:
      this instance.
    • setOptSeparator

      public OptionFormatter.Builder setOptSeparator(String optSeparator)
      Sets the separator displayed between a long option and short options. Typically ',' or ' '.
      Parameters:
      optSeparator - the separator.
      Returns:
      this
      Since:
      1.3
    • setSyntaxFormatFunction

      public OptionFormatter.Builder setSyntaxFormatFunction(BiFunction<OptionFormatter,Boolean,String> syntaxFormatFunction)
      Specifies the function to convert an OptionFormatter into the syntax format for the option.
      Parameters:
      syntaxFormatFunction - The function to convert an OptionFormatter into the syntax format for the option.
      Returns:
      this
    • toArgName

      public String toArgName(String argName)
      A helper method to format any string as an argument name based on this builder.
      Parameters:
      argName - the name of the argument.
      Returns:
      the formatted argument.