Class CommandDescription


  • public class CommandDescription
    extends java.lang.Object
    Describes a command for help display and widget integration.

    Uses a builder pattern and record-style accessors. Instances are immutable once built.

    Example:

     CommandDescription desc = CommandDescription.builder()
         .mainDescription(List.of(new AttributedString("list files")))
         .argument(new ArgumentDescription("path"))
         .option("-l --long", List.of(new AttributedString("long format")))
         .build();
     
    Since:
    4.0
    See Also:
    ArgumentDescription, Command.describe(List)
    • Method Detail

      • mainDescription

        public java.util.List<AttributedString> mainDescription()
        Returns the main description lines.
        Returns:
        the main description, never null
      • arguments

        public java.util.List<ArgumentDescription> arguments()
        Returns the argument descriptions.
        Returns:
        the arguments, never null
      • options

        public java.util.Map<java.lang.String,​java.util.List<AttributedString>> options()
        Returns the option descriptions, keyed by option syntax.
        Returns:
        the options map, never null
      • isValid

        public boolean isValid()
        Returns whether this description represents a valid command.
        Returns:
        true if valid
      • isCommand

        public boolean isCommand()
        Returns whether this description represents a command (as opposed to a method or syntax).
        Returns:
        true if this is a command description
      • isSubcommand

        public boolean isSubcommand()
        Returns whether this description represents a subcommand.
        Returns:
        true if this is a subcommand
      • optionWithValue

        public boolean optionWithValue​(java.lang.String option)
        Returns whether the specified option takes a value.

        An option is considered to take a value if its key in the options map contains an = character (e.g., "-o --output=FILE").

        Parameters:
        option - the option to check (e.g., "-o")
        Returns:
        true if the option takes a value
      • optionDescription

        public AttributedString optionDescription​(java.lang.String key)
        Returns the first line of description for the specified option key.
        Parameters:
        key - the option key as it appears in the options map
        Returns:
        the first description line, or an empty string if none
      • isHighlighted

        public boolean isHighlighted()
        Returns whether the command should be highlighted.
        Returns:
        true if highlighted
      • errorPattern

        public java.util.regex.Pattern errorPattern()
        Returns the pattern for identifying errors, or null.
        Returns:
        the error pattern
      • errorIndex

        public int errorIndex()
        Returns the error index, or -1 if none.
        Returns:
        the error index