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 Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<ArgumentDescription> arguments()
      Returns the argument descriptions.
      static CommandDescription.Builder builder()
      Creates a new builder.
      int errorIndex()
      Returns the error index, or -1 if none.
      java.util.regex.Pattern errorPattern()
      Returns the pattern for identifying errors, or null.
      boolean isCommand()
      Returns whether this description represents a command (as opposed to a method or syntax).
      boolean isHighlighted()
      Returns whether the command should be highlighted.
      boolean isSubcommand()
      Returns whether this description represents a subcommand.
      boolean isValid()
      Returns whether this description represents a valid command.
      java.util.List<org.jline.utils.AttributedString> mainDescription()
      Returns the main description lines.
      org.jline.utils.AttributedString optionDescription​(java.lang.String key)
      Returns the first line of description for the specified option key.
      java.util.Map<java.lang.String,​java.util.List<org.jline.utils.AttributedString>> options()
      Returns the option descriptions, keyed by option syntax.
      boolean optionWithValue​(java.lang.String option)
      Returns whether the specified option takes a value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • mainDescription

        public java.util.List<org.jline.utils.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<org.jline.utils.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 org.jline.utils.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