18
18
from functools import total_ordering
19
19
from itertools import starmap
20
20
from string import Template
21
- from typing import Any , Dict , List , Sequence , Tuple , Mapping
21
+ from typing import Any , Dict , List , Mapping
22
22
from typing import Optional as Opt
23
- from typing import Union
23
+ from typing import Sequence , Tuple , Union
24
24
25
25
# version detector. Precedence: installed dist, git, 'UNKNOWN'
26
26
try :
@@ -55,10 +55,9 @@ def fglob(fglob: str):
55
55
'''Glob files'''
56
56
return {
57
57
'__glob__' : fglob ,
58
- 'bash' : '_shtab_compgen_files' , # Uses `__glob__` internally
58
+ 'bash' : '_shtab_compgen_files' , # Uses `__glob__` internally
59
59
'zsh' : f"_files -g '{ fglob } '" ,
60
- 'tcsh' : f'f:{ fglob } ' ,
61
- }
60
+ 'tcsh' : f'f:{ fglob } ' ,}
62
61
63
62
64
63
class _ShtabPrintCompletionAction (Action ):
@@ -140,9 +139,11 @@ def complete2pattern(opt_complete, shell: str, choice_type2fn) -> str:
140
139
return choice_type2fn [opt_complete ]
141
140
142
141
143
- def bash_complete2compgen (opt_complete : Mapping [str , str ], shell : str ,
144
- choice_type2fn : Mapping [str , str ],
145
- ) -> Tuple [str , Tuple [str ]]:
142
+ def bash_complete2compgen (
143
+ opt_complete : Mapping [str , str ],
144
+ shell : str ,
145
+ choice_type2fn : Mapping [str , str ],
146
+ ) -> Tuple [str , Tuple [str ]]:
146
147
# Same inputs as `complete2pattern`
147
148
options = []
148
149
if isinstance (opt_complete , dict ):
@@ -220,11 +221,11 @@ def recurse(parser, prefix):
220
221
221
222
if hasattr (positional , "complete" ):
222
223
# shtab `.complete = ...` functions
223
- comp_gen , comp_genopts = bash_complete2compgen (positional .complete , "bash" , choice_type2fn )
224
+ comp_gen , comp_genopts = bash_complete2compgen (positional .complete , "bash" ,
225
+ choice_type2fn )
224
226
compgens .extend ([
225
227
f"{ prefix } _pos_{ i } _COMPGEN={ comp_gen } " ,
226
- f"{ prefix } _pos_{ i } _COMPGEN_options={ bash_listify (comp_genopts )} " ,
227
- ])
228
+ f"{ prefix } _pos_{ i } _COMPGEN_options={ bash_listify (comp_genopts )} " ,])
228
229
229
230
if positional .choices :
230
231
# choices (including subparsers & shtab `.complete` functions)
@@ -238,8 +239,7 @@ def recurse(parser, prefix):
238
239
log .debug (f"Choice.{ choice .type } :{ prefix } :{ positional .dest } " )
239
240
compgens .extend ([
240
241
f"{ prefix } _pos_{ i } _COMPGEN={ choice_type2fn [choice .type ]} " ,
241
- f"{ prefix } _pos_{ i } _COMPGEN_options=()" ,
242
- ])
242
+ f"{ prefix } _pos_{ i } _COMPGEN_options=()" ,])
243
243
elif isinstance (positional .choices , dict ):
244
244
# subparser, so append to list of subparsers & recurse
245
245
log .debug ("subcommand:%s" , choice )
@@ -269,7 +269,8 @@ def recurse(parser, prefix):
269
269
this_positional_choices .append (str (choice ))
270
270
271
271
if this_positional_choices :
272
- choices .append (f"{ prefix } _pos_{ i } _choices={ bash_listify (this_positional_choices )} " )
272
+ choices .append (
273
+ f"{ prefix } _pos_{ i } _choices={ bash_listify (this_positional_choices )} " )
273
274
274
275
# skip default `nargs` values
275
276
if positional .nargs not in (None , "1" , "?" ):
@@ -290,7 +291,8 @@ def recurse(parser, prefix):
290
291
for option_string in optional .option_strings :
291
292
if hasattr (optional , "complete" ):
292
293
# shtab `.complete = ...` functions
293
- comp_gen , comp_genopts = bash_complete2compgen (optional .complete , "bash" , choice_type2fn )
294
+ comp_gen , comp_genopts = bash_complete2compgen (optional .complete , "bash" ,
295
+ choice_type2fn )
294
296
compgens .extend ([
295
297
f"{ prefix } _{ wordify (option_string )} _COMPGEN={ comp_gen } " ,
296
298
f"{ prefix } _{ wordify (option_string )} _COMPGEN_options={ bash_listify (comp_genopts )} " ,
@@ -306,14 +308,15 @@ def recurse(parser, prefix):
306
308
log .debug (f"Choice.{ choice .type } :{ prefix } :{ optional .dest } " )
307
309
compgens .extend ([
308
310
f"{ prefix } _{ wordify (option_string )} _COMPGEN={ choice_type2fn [choice .type ]} " ,
309
- f"{ prefix } _{ wordify (option_string )} _COMPGEN_options=()" ,
310
- ])
311
+ f"{ prefix } _{ wordify (option_string )} _COMPGEN_options=()" ,])
311
312
else :
312
313
# simple choice
313
314
this_optional_choices .append (str (choice ))
314
315
315
316
if this_optional_choices :
316
- choices .append (f"{ prefix } _{ wordify (option_string )} _choices={ bash_listify (this_optional_choices )} " )
317
+ choices .append (
318
+ f"{ prefix } _{ wordify (option_string )} _choices={ bash_listify (this_optional_choices )} "
319
+ )
317
320
318
321
# Check for nargs.
319
322
if optional .nargs is not None and optional .nargs != 1 :
0 commit comments