Class Completers.OptDesc

java.lang.Object
org.jline.builtins.Completers.OptDesc
Enclosing class:
Completers

public static class Completers.OptDesc extends Object
Describes a command-line option for completion.

This class holds information about command options, including short and long forms, descriptions, and value completers for options that take arguments.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected default constructor for subclasses.
     
    OptDesc(String shortOption, String longOption)
    Command option description.
     
    OptDesc(String shortOption, String longOption, String description)
    Command option description.
     
    OptDesc(String shortOption, String longOption, String description, org.jline.reader.Completer valueCompleter)
    Command option description.
     
    OptDesc(String shortOption, String longOption, org.jline.reader.Completer valueCompleter)
    Command option description.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static List<Completers.OptDesc>
    compile(Map<String,List<String>> optionValues, Collection<String> options)
    Compiles a list of OptDesc objects from option values and options.
    protected void
    completeOption(org.jline.reader.LineReader reader, org.jline.reader.ParsedLine commandLine, List<org.jline.reader.Candidate> candidates, boolean longOpt)
    Completes an option based on whether it's a short or long option.
    protected boolean
    completeValue(org.jline.reader.LineReader reader, org.jline.reader.ParsedLine commandLine, List<org.jline.reader.Candidate> candidates, String curBuf, String partialValue)
    Completes the value for an option.
    Gets the description of the option.
    protected boolean
    Determines if this option takes a value.
    Gets the long form of the option.
    protected boolean
    match(String option)
    Determines if this option matches the specified option string.
    void
    setValueCompleter(org.jline.reader.Completer valueCompleter)
    Sets the value completer for this option.
    Gets the short form of the option.
    protected boolean
    Determines if this option starts with the specified prefix.
    protected org.jline.reader.Completer
    Gets the value completer for this option.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OptDesc

      public OptDesc(String shortOption, String longOption, String description, org.jline.reader.Completer valueCompleter)
      Command option description. If option does not have short/long option assign to it null value. If option does not have value set valueCompleter = NullCompleter.INSTANCE
      Parameters:
      shortOption - short option
      longOption - long option
      description - short option description
      valueCompleter - option value completer
    • OptDesc

      public OptDesc(String shortOption, String longOption, org.jline.reader.Completer valueCompleter)
      Command option description. If option does not have short/long option assign to it null value. If option does not have value set valueCompleter = NullCompleter.INSTANCE
      Parameters:
      shortOption - short option
      longOption - long option
      valueCompleter - option value completer
    • OptDesc

      public OptDesc(String shortOption, String longOption, String description)
      Command option description. If option does not have short/long option assign to it null value.
      Parameters:
      shortOption - short option
      longOption - long option
      description - short option description
    • OptDesc

      public OptDesc(String shortOption, String longOption)
      Command option description. If option does not have short/long option assign to it null value.
      Parameters:
      shortOption - short option
      longOption - long option
    • OptDesc

      protected OptDesc()
      Protected default constructor for subclasses.
  • Method Details

    • compile

      protected static List<Completers.OptDesc> compile(Map<String,List<String>> optionValues, Collection<String> options)
      Compiles a list of OptDesc objects from option values and options.

      Creates OptDesc objects for both options with values and options without values.

      Parameters:
      optionValues - a map of option names to their possible values
      options - a collection of option names that don't take values
      Returns:
      a list of OptDesc objects
    • setValueCompleter

      public void setValueCompleter(org.jline.reader.Completer valueCompleter)
      Sets the value completer for this option.
      Parameters:
      valueCompleter - the completer for option values
    • longOption

      public String longOption()
      Gets the long form of the option.
      Returns:
      the long option string, or null if not set
    • shortOption

      public String shortOption()
      Gets the short form of the option.
      Returns:
      the short option string, or null if not set
    • description

      public String description()
      Gets the description of the option.
      Returns:
      the option description, or null if not set
    • hasValue

      protected boolean hasValue()
      Determines if this option takes a value.
      Returns:
      true if the option takes a value, false otherwise
    • valueCompleter

      protected org.jline.reader.Completer valueCompleter()
      Gets the value completer for this option.
      Returns:
      the value completer, or null if not set
    • completeOption

      protected void completeOption(org.jline.reader.LineReader reader, org.jline.reader.ParsedLine commandLine, List<org.jline.reader.Candidate> candidates, boolean longOpt)
      Completes an option based on whether it's a short or long option.

      Adds appropriate candidates for the option based on its type and whether it takes a value.

      Parameters:
      reader - the line reader
      commandLine - the parsed command line
      candidates - the list to add completion candidates to
      longOpt - true if completing long options, false for short options
    • completeValue

      protected boolean completeValue(org.jline.reader.LineReader reader, org.jline.reader.ParsedLine commandLine, List<org.jline.reader.Candidate> candidates, String curBuf, String partialValue)
      Completes the value for an option.

      Uses the option's value completer to generate completion candidates for the option value.

      Parameters:
      reader - the line reader
      commandLine - the parsed command line
      candidates - the list to add completion candidates to
      curBuf - the current buffer up to the cursor
      partialValue - the partial value to complete
      Returns:
      true if any candidates were added, false otherwise
    • match

      protected boolean match(String option)
      Determines if this option matches the specified option string.
      Parameters:
      option - the option string to check
      Returns:
      true if this option matches the specified string, false otherwise
    • startsWith

      protected boolean startsWith(String option)
      Determines if this option starts with the specified prefix.
      Parameters:
      option - the prefix to check
      Returns:
      true if this option starts with the specified prefix, false otherwise