Class ArgumentCompleter

  • All Implemented Interfaces:
    Completer

    public class ArgumentCompleter
    extends java.lang.Object
    implements Completer
    A Completer implementation that invokes a child completer using the appropriate separator argument. This can be used instead of the individual completers having to know about argument parsing semantics.
    Since:
    2.3
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ArgumentCompleter.ArgumentLine
      A simple implementation of ParsedLine for argument completion.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void complete​(LineReader reader, ParsedLine line, java.util.List<Candidate> candidates)
      Populates candidates with a list of possible completions for the command line.
      java.util.List<Completer> getCompleters()
      Returns the list of completers used inside this ArgumentCompleter.
      boolean isStrict()
      Returns whether a completion at argument index N will success if all the completions from arguments 0-(N-1) also succeed.
      void setStrict​(boolean strict)
      If true, a completion at argument index N will only succeed if all the completions from 0-(N-1) also succeed.
      void setStrictCommand​(boolean strictCommand)
      If true, a completion at argument index N will only succeed if all the completions from 1-(N-1) also succeed.
      • Methods inherited from class java.lang.Object

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

      • ArgumentCompleter

        public ArgumentCompleter​(java.util.Collection<Completer> completers)
        Create a new completer.
        Parameters:
        completers - The embedded completers
      • ArgumentCompleter

        public ArgumentCompleter​(Completer... completers)
        Create a new completer.
        Parameters:
        completers - The embedded completers
    • Method Detail

      • setStrict

        public void setStrict​(boolean strict)
        If true, a completion at argument index N will only succeed if all the completions from 0-(N-1) also succeed.
        Parameters:
        strict - the strict flag
      • setStrictCommand

        public void setStrictCommand​(boolean strictCommand)
        If true, a completion at argument index N will only succeed if all the completions from 1-(N-1) also succeed.
        Parameters:
        strictCommand - the strictCommand flag
      • isStrict

        public boolean isStrict()
        Returns whether a completion at argument index N will success if all the completions from arguments 0-(N-1) also succeed.
        Returns:
        True if strict.
        Since:
        2.3
      • getCompleters

        public java.util.List<Completer> getCompleters()
        Returns the list of completers used inside this ArgumentCompleter.
        Returns:
        The list of completers.
        Since:
        2.3
      • complete

        public void complete​(LineReader reader,
                             ParsedLine line,
                             java.util.List<Candidate> candidates)
        Description copied from interface: Completer
        Populates candidates with a list of possible completions for the command line.

        The list of candidates will be sorted and filtered by the LineReader, so that the list of candidates displayed to the user will usually be smaller than the list given by the completer. Thus it is not necessary for the completer to do any matching based on the current buffer. On the contrary, in order for the typo matcher to work, all possible candidates for the word being completed should be returned.

        Implementations should add Candidate objects to the candidates list. Each candidate can include additional information such as descriptions, groups, and display attributes that will be used when presenting completion options to the user.

        This method is called by the LineReader when the user requests completion, typically by pressing the Tab key.

        Specified by:
        complete in interface Completer
        Parameters:
        reader - The line reader instance that is requesting completion
        line - The parsed command line containing the current input state
        candidates - The List of candidates to populate with completion options
        See Also:
        Candidate