- java.lang.Object
-
- org.jline.shell.CommandDescription
-
public class CommandDescription extends java.lang.ObjectDescribes 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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandDescription.BuilderBuilder forCommandDescriptioninstances.
-
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.Builderbuilder()Creates a new builder.interrorIndex()Returns the error index, or -1 if none.java.util.regex.PatternerrorPattern()Returns the pattern for identifying errors, or null.booleanisCommand()Returns whether this description represents a command (as opposed to a method or syntax).booleanisHighlighted()Returns whether the command should be highlighted.booleanisSubcommand()Returns whether this description represents a subcommand.booleanisValid()Returns whether this description represents a valid command.java.util.List<org.jline.utils.AttributedString>mainDescription()Returns the main description lines.org.jline.utils.AttributedStringoptionDescription(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.booleanoptionWithValue(java.lang.String option)Returns whether the specified option takes a value.
-
-
-
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
-
builder
public static CommandDescription.Builder builder()
Creates a new builder.- Returns:
- a new builder
-
-