Class OptionFormatter

java.lang.Object
org.apache.commons.cli.help.OptionFormatter

public final class OptionFormatter extends Object
The definition of how to display Option attributes.
Since:
1.10.0
  • Field Details

  • Method Details

    • builder

      Creates a new builder.
      Returns:
      a new builder.
    • from

      public static OptionFormatter from(Option option)
      Construct the OptionFormatter from an Option using the default OptionFormatter.Builder.
      Parameters:
      option - the option to format.
      Returns:
      an OptionFormatter for the specified @{code option}.
    • getArgName

      public String getArgName()
      Gets the argument name wrapped in the argument name delimiters.
      • If option has no arguments an empty string is returned
      • If the argument name is not set the default argument name is used.
      Returns:
      The argument name wrapped in the argument name delimiters or an empty string.
    • getBothOpt

      public String getBothOpt()
      Gets both options separated by the specified option separator. Correctly handles the case where one option is not specified.
      Returns:
      The one or both of the short and/or long Opt with the associate prefixes.
    • getDescription

      Gets the description for the option. This will include any deprecation notices if the deprecated format function has been set.
      Returns:
      The Description from the option or an empty string is no description was provided and the option is not deprecated.
    • getLongOpt

      public String getLongOpt()
      Gets the long Opt from the @{link Option} with the associate prefix.
      Returns:
      The long Opt from the @{link Option} with the associate prefix or an empty string.
    • getOpt

      public String getOpt()
      Gets the Opt from the @{link Option} with the associate prefix.
      Returns:
      The Opt from the @{link Option} with the associate prefix or an empty string.
    • getSince

      public String getSince()
      Gets the "since" value from the Option.
      Returns:
      The since valeu from the option or "--" if no since value was set.
    • isRequired

      public boolean isRequired()
      Gets the required flag from the enclosed Option.
      Returns:
      The required flag from the enclosed Option.
    • toOptional

      public String toOptional(String text)
      Wraps the provided text in the optional delimiters.
      Parameters:
      text - the text to wrap.
      Returns:
      The text wrapped in the optional delimiters or an eppty string of the text is null or an empty string.
    • toSyntaxOption

      Gets the syntax format for this option.
      Returns:
      the syntax format for this option as specified by the syntaxFormatFunction.
    • toSyntaxOption

      public String toSyntaxOption(boolean isRequired)
      Gets the syntax format for this option.
      Parameters:
      isRequired - if true the options is printed as a required option, otherwise it is optional.
      Returns:
      the syntax format for this option as specified by the syntaxFormatFunction.