@@ -106,18 +106,18 @@ def tokens_for_completion(line, endidx):
106
106
class CompletionFinder (argcomplete .CompletionFinder ):
107
107
"""Hijack the functor from argcomplete to call AutoCompleter"""
108
108
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 ,
109
+ def __call__ (self , argument_parser , completer = None , always_complete_options = True , exit_method = os ._exit ,
110
+ output_stream = None , exclude = None , validator = None , print_suppressed = False , append_space = None ,
111
111
default_completer = DEFAULT_COMPLETER ):
112
112
"""
113
113
:param argument_parser: The argument parser to autocomplete on
114
114
:type argument_parser: :class:`argparse.ArgumentParser`
115
115
: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.
116
+ Controls the autocompletion of option strings if an option string opening character (normally ``-``) has
117
+ not 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
119
+ options with no long variant will be suggested. If ``short``, short options and long options with no
120
+ short variant will be suggested.
121
121
:type always_complete_options: boolean or string
122
122
:param exit_method:
123
123
Method used to stop the program after printing completions. Defaults to :meth:`os._exit`. If you want to
@@ -126,8 +126,8 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
126
126
:param exclude: List of strings representing options to be omitted from autocompletion
127
127
:type exclude: iterable
128
128
: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)
129
+ Function to filter all completions through before returning (called with two string arguments,
130
+ completion and prefix; return value is evaluated as a boolean)
131
131
:type validator: callable
132
132
:param print_suppressed:
133
133
Whether or not to autocomplete options that have the ``help=argparse.SUPPRESS`` keyword argument set.
@@ -142,18 +142,18 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
142
142
143
143
Produces tab completions for ``argument_parser``. See module docs for more info.
144
144
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.
145
+ Argcomplete only executes actions if their class is known not to have side effects. Custom action classes
146
+ can be added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer
147
+ argument, or their execution is otherwise desirable.
148
148
"""
149
149
# Older versions of argcomplete have fewer keyword arguments
150
150
if sys .version_info >= (3 , 5 ):
151
151
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 )
152
+ validator = validator , print_suppressed = print_suppressed , append_space = append_space ,
153
+ default_completer = default_completer )
154
154
else :
155
155
self .__init__ (argument_parser , always_complete_options = always_complete_options , exclude = exclude ,
156
- validator = validator , print_suppressed = print_suppressed )
156
+ validator = validator , print_suppressed = print_suppressed )
157
157
158
158
if "_ARGCOMPLETE" not in os .environ :
159
159
# not an argument completion invocation
@@ -171,10 +171,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
171
171
argcomplete .debug ("Unable to open fd 8 for writing, quitting" )
172
172
exit_method (1 )
173
173
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
-
178
174
ifs = os .environ .get ("_ARGCOMPLETE_IFS" , "\013 " )
179
175
if len (ifs ) != 1 :
180
176
argcomplete .debug ("Invalid value for IFS, quitting [{v}]" .format (v = ifs ))
@@ -190,8 +186,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
190
186
#
191
187
# Replaced with our own tokenizer function
192
188
##############################
193
-
194
- # cword_prequote, cword_prefix, cword_suffix, comp_words, last_wordbreak_pos = split_line(comp_line, comp_point)
195
189
tokens , _ , begidx , endidx = tokens_for_completion (comp_line , comp_point )
196
190
197
191
# _ARGCOMPLETE is set by the shell script to tell us where comp_words
@@ -259,9 +253,13 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
259
253
exit_method (0 )
260
254
261
255
262
- def bash_complete (action , show_hint : bool = True ):
263
- """Helper function to configure an argparse action to fall back to bash completion"""
256
+ def bash_complete (action , show_hint : bool = True ):
257
+ """Helper function to configure an argparse action to fall back to bash completion.
258
+
259
+ This function tags a parameter for bash completion, bypassing the autocompleter (for file input).
260
+ """
264
261
def complete_none (* args , ** kwargs ):
265
262
return None
263
+
266
264
setattr (action , ACTION_SUPPRESS_HINT , not show_hint )
267
265
setattr (action , ACTION_ARG_CHOICES , (complete_none ,))
0 commit comments