88
99import shtab # for completion magic
1010
11- TXT_FILE = {
12- "bash" : "_shtab_greeter_compgen_TXTFiles" ,
13- "zsh" : "_files -g '(*.txt|*.TXT)'" ,
14- }
11+ TXT_FILE = {"bash" : "_shtab_greeter_compgen_TXTFiles" , "zsh" : "_files -g '(*.txt|*.TXT)'" }
1512PREAMBLE = {
1613 "bash" : """
1714# $1=COMP_WORDS[1]
2017 compgen -f -X '!*?.txt' -- $1
2118 compgen -f -X '!*?.TXT' -- $1
2219}
23- """ ,
24- "zsh" : "" ,
25- }
20+ """ , "zsh" : "" }
2621
2722
2823def process (args ):
29- print (
30- "received <input_txt>=%r --input-file=%r --output-name=%r"
31- % (args .input_txt , args .input_file , args .output_name )
32- )
24+ print ("received <input_txt>=%r --input-file=%r --output-name=%r" %
25+ (args .input_txt , args .input_file , args .output_name ))
3326
3427
3528def get_main_parser ():
@@ -40,9 +33,7 @@ def get_main_parser():
4033 subparsers .dest = "subcommand"
4134
4235 parser = subparsers .add_parser ("completion" , help = "print tab completion" )
43- shtab .add_argument_to (
44- parser , "shell" , parent = main_parser , preamble = PREAMBLE
45- ) # magic!
36+ shtab .add_argument_to (parser , "shell" , parent = main_parser , preamble = PREAMBLE ) # magic!
4637
4738 parser = subparsers .add_parser ("process" , help = "parse files" )
4839 # `*.txt` file tab completion
@@ -52,11 +43,11 @@ def get_main_parser():
5243 parser .add_argument (
5344 "-o" ,
5445 "--output-name" ,
55- help = (
56- "output file name. Completes directory names to avoid users"
57- " accidentally overwriting existing files."
58- ),
59- ). complete = shtab . DIRECTORY # directory tab completion builtin shortcut
46+ help = ("output file name. Completes directory names to avoid users"
47+ " accidentally overwriting existing files." ),
48+ ). complete = shtab . DIRECTORY
49+ # directory tab completion builtin shortcut
50+
6051 parser .set_defaults (func = process )
6152 return main_parser
6253
0 commit comments