Class Completers.OptDesc

  • Enclosing class:
    Completers

    public static class Completers.OptDesc
    extends java.lang.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 OptDesc()
      Protected default constructor for subclasses.
        OptDesc​(java.lang.String shortOption, java.lang.String longOption)
      Command option description.
        OptDesc​(java.lang.String shortOption, java.lang.String longOption, java.lang.String description)
      Command option description.
        OptDesc​(java.lang.String shortOption, java.lang.String longOption, java.lang.String description, org.jline.reader.Completer valueCompleter)
      Command option description.
        OptDesc​(java.lang.String shortOption, java.lang.String longOption, org.jline.reader.Completer valueCompleter)
      Command option description.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static java.util.List<Completers.OptDesc> compile​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> optionValues, java.util.Collection<java.lang.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, java.util.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, java.util.List<org.jline.reader.Candidate> candidates, java.lang.String curBuf, java.lang.String partialValue)
      Completes the value for an option.
      java.lang.String description()
      Gets the description of the option.
      protected boolean hasValue()
      Determines if this option takes a value.
      java.lang.String longOption()
      Gets the long form of the option.
      protected boolean match​(java.lang.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.
      java.lang.String shortOption()
      Gets the short form of the option.
      protected boolean startsWith​(java.lang.String option)
      Determines if this option starts with the specified prefix.
      protected org.jline.reader.Completer valueCompleter()
      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 Detail

      • OptDesc

        public OptDesc​(java.lang.String shortOption,
                       java.lang.String longOption,
                       java.lang.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​(java.lang.String shortOption,
                       java.lang.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​(java.lang.String shortOption,
                       java.lang.String longOption,
                       java.lang.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​(java.lang.String shortOption,
                       java.lang.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 Detail

      • compile

        protected static java.util.List<Completers.OptDesc> compile​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> optionValues,
                                                                    java.util.Collection<java.lang.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 java.lang.String longOption()
        Gets the long form of the option.
        Returns:
        the long option string, or null if not set
      • shortOption

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

        public java.lang.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,
                                      java.util.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,
                                        java.util.List<org.jline.reader.Candidate> candidates,
                                        java.lang.String curBuf,
                                        java.lang.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​(java.lang.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​(java.lang.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