]>
Commit | Line | Data |
---|---|---|
56d1912f JMF |
1 | #!/usr/bin/env python |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import optparse | |
5 | import os | |
6 | from os.path import dirname as dirn | |
7 | import sys | |
8 | ||
95240b80 | 9 | sys.path.insert(0, dirn(dirn((os.path.abspath(__file__))))) |
cefecac1 U |
10 | import youtube_dlc |
11 | from youtube_dlc.utils import shell_quote | |
56d1912f | 12 | |
cefecac1 | 13 | FISH_COMPLETION_FILE = 'youtube-dlc.fish' |
56d1912f JMF |
14 | FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in' |
15 | ||
16 | EXTRA_ARGS = { | |
efe87a10 | 17 | 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'], |
56d1912f JMF |
18 | 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'], |
19 | ||
20 | # Options that need a file parameter | |
21 | 'download-archive': ['--require-parameter'], | |
22 | 'cookies': ['--require-parameter'], | |
23 | 'load-info': ['--require-parameter'], | |
24 | 'batch-file': ['--require-parameter'], | |
25 | } | |
26 | ||
5f6a1245 | 27 | |
56d1912f JMF |
28 | def build_completion(opt_parser): |
29 | commands = [] | |
30 | ||
31 | for group in opt_parser.option_groups: | |
32 | for option in group.option_list: | |
33 | long_option = option.get_opt_string().strip('-') | |
cefecac1 | 34 | complete_cmd = ['complete', '--command', 'youtube-dlc', '--long-option', long_option] |
56d1912f JMF |
35 | if option._short_opts: |
36 | complete_cmd += ['--short-option', option._short_opts[0].strip('-')] | |
37 | if option.help != optparse.SUPPRESS_HELP: | |
38 | complete_cmd += ['--description', option.help] | |
39 | complete_cmd.extend(EXTRA_ARGS.get(long_option, [])) | |
40 | commands.append(shell_quote(complete_cmd)) | |
41 | ||
42 | with open(FISH_COMPLETION_TEMPLATE) as f: | |
43 | template = f.read() | |
44 | filled_template = template.replace('{{commands}}', '\n'.join(commands)) | |
45 | with open(FISH_COMPLETION_FILE, 'w') as f: | |
46 | f.write(filled_template) | |
47 | ||
582be358 | 48 | |
cefecac1 | 49 | parser = youtube_dlc.parseOpts()[0] |
56d1912f | 50 | build_completion(parser) |