]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/fish-completion.py
c2f2387980d0867adc3cea4c3e14047fdaf1aa28
2 from __future__
import unicode_literals
6 from os
.path
import dirname
as dirn
9 sys
.path
.append(dirn(dirn((os
.path
.abspath(__file__
)))))
11 from youtube_dl
.utils
import shell_quote
13 FISH_COMPLETION_FILE
= 'youtube-dl.fish'
14 FISH_COMPLETION_TEMPLATE
= 'devscripts/fish-completion.in'
17 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
19 # Options that need a file parameter
20 'download-archive': ['--require-parameter'],
21 'cookies': ['--require-parameter'],
22 'load-info': ['--require-parameter'],
23 'batch-file': ['--require-parameter'],
27 def build_completion(opt_parser
):
30 for group
in opt_parser
.option_groups
:
31 for option
in group
.option_list
:
32 long_option
= option
.get_opt_string().strip('-')
33 complete_cmd
= ['complete', '--command', 'youtube-dl', '--long-option', long_option
]
34 if option
._short
_opts
:
35 complete_cmd
+= ['--short-option', option
._short
_opts
[0].strip('-')]
36 if option
.help != optparse
.SUPPRESS_HELP
:
37 complete_cmd
+= ['--description', option
.help]
38 complete_cmd
.extend(EXTRA_ARGS
.get(long_option
, []))
39 commands
.append(shell_quote(complete_cmd
))
41 with open(FISH_COMPLETION_TEMPLATE
) as f
:
43 filled_template
= template
.replace('{{commands}}', '\n'.join(commands
))
44 with open(FISH_COMPLETION_FILE
, 'w') as f
:
45 f
.write(filled_template
)
47 parser
= youtube_dl
.parseOpts()[0]
48 build_completion(parser
)