1616 except AttributeError :
1717 DEFAULT_COMPLETER = argcomplete .completers .FilesCompleter ()
1818
19- from cmd2 .argparse_completer import ACTION_ARG_CHOICES , ACTION_SUPPRESS_HINT
2019 from contextlib import redirect_stdout
2120 import copy
2221 from io import StringIO
@@ -106,18 +105,18 @@ def tokens_for_completion(line, endidx):
106105 class CompletionFinder (argcomplete .CompletionFinder ):
107106 """Hijack the functor from argcomplete to call AutoCompleter"""
108107
109- def __call__ (self , argument_parser , completer = None , always_complete_options = True , exit_method = os ._exit , output_stream = None ,
110- exclude = None , validator = None , print_suppressed = False , append_space = None ,
108+ def __call__ (self , argument_parser , completer = None , always_complete_options = True , exit_method = os ._exit ,
109+ output_stream = None , exclude = None , validator = None , print_suppressed = False , append_space = None ,
111110 default_completer = DEFAULT_COMPLETER ):
112111 """
113112 :param argument_parser: The argument parser to autocomplete on
114113 :type argument_parser: :class:`argparse.ArgumentParser`
115114 :param always_complete_options:
116- Controls the autocompletion of option strings if an option string opening character (normally ``-``) has not
117- been entered. If ``True`` (default), both short (``-x``) and long (``--x``) option strings will be
118- suggested. If ``False``, no option strings will be suggested. If ``long``, long options and short options
119- with no long variant will be suggested. If ``short``, short options and long options with no short variant
120- will be suggested.
115+ Controls the autocompletion of option strings if an option string opening character (normally ``-``) has
116+ not been entered. If ``True`` (default), both short (``-x``) and long (``--x``) option strings will be
117+ suggested. If ``False``, no option strings will be suggested. If ``long``, long options and short
118+ options with no long variant will be suggested. If ``short``, short options and long options with no
119+ short variant will be suggested.
121120 :type always_complete_options: boolean or string
122121 :param exit_method:
123122 Method used to stop the program after printing completions. Defaults to :meth:`os._exit`. If you want to
@@ -126,8 +125,8 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
126125 :param exclude: List of strings representing options to be omitted from autocompletion
127126 :type exclude: iterable
128127 :param validator:
129- Function to filter all completions through before returning (called with two string arguments, completion
130- and prefix; return value is evaluated as a boolean)
128+ Function to filter all completions through before returning (called with two string arguments,
129+ completion and prefix; return value is evaluated as a boolean)
131130 :type validator: callable
132131 :param print_suppressed:
133132 Whether or not to autocomplete options that have the ``help=argparse.SUPPRESS`` keyword argument set.
@@ -142,18 +141,18 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
142141
143142 Produces tab completions for ``argument_parser``. See module docs for more info.
144143
145- Argcomplete only executes actions if their class is known not to have side effects. Custom action classes can be
146- added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer argument, or
147- their execution is otherwise desirable.
144+ Argcomplete only executes actions if their class is known not to have side effects. Custom action classes
145+ can be added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer
146+ argument, or their execution is otherwise desirable.
148147 """
149148 # Older versions of argcomplete have fewer keyword arguments
150149 if sys .version_info >= (3 , 5 ):
151150 self .__init__ (argument_parser , always_complete_options = always_complete_options , exclude = exclude ,
152- validator = validator , print_suppressed = print_suppressed , append_space = append_space ,
153- default_completer = default_completer )
151+ validator = validator , print_suppressed = print_suppressed , append_space = append_space ,
152+ default_completer = default_completer )
154153 else :
155154 self .__init__ (argument_parser , always_complete_options = always_complete_options , exclude = exclude ,
156- validator = validator , print_suppressed = print_suppressed )
155+ validator = validator , print_suppressed = print_suppressed )
157156
158157 if "_ARGCOMPLETE" not in os .environ :
159158 # not an argument completion invocation
@@ -171,10 +170,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
171170 argcomplete .debug ("Unable to open fd 8 for writing, quitting" )
172171 exit_method (1 )
173172
174- # print("", stream=debug_stream)
175- # for v in "COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY _ARGCOMPLETE_COMP_WORDBREAKS COMP_WORDS".split():
176- # print(v, os.environ[v], stream=debug_stream)
177-
178173 ifs = os .environ .get ("_ARGCOMPLETE_IFS" , "\013 " )
179174 if len (ifs ) != 1 :
180175 argcomplete .debug ("Invalid value for IFS, quitting [{v}]" .format (v = ifs ))
@@ -190,8 +185,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
190185 #
191186 # Replaced with our own tokenizer function
192187 ##############################
193-
194- # cword_prequote, cword_prefix, cword_suffix, comp_words, last_wordbreak_pos = split_line(comp_line, comp_point)
195188 tokens , _ , begidx , endidx = tokens_for_completion (comp_line , comp_point )
196189
197190 # _ARGCOMPLETE is set by the shell script to tell us where comp_words
@@ -257,11 +250,3 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
257250 output_stream .flush ()
258251 argcomplete .debug_stream .flush ()
259252 exit_method (0 )
260-
261-
262- def bash_complete (action , show_hint : bool = True ):
263- """Helper function to configure an argparse action to fall back to bash completion"""
264- def complete_none (* args , ** kwargs ):
265- return None
266- setattr (action , ACTION_SUPPRESS_HINT , not show_hint )
267- setattr (action , ACTION_ARG_CHOICES , (complete_none ,))
0 commit comments