]>
Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/fish-completion.py
f4aaf0201f5a43341a0dfa1de3eb1087a293485b
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'],
26 def build_completion(opt_parser
):
29 for group
in opt_parser
.option_groups
:
30 for option
in group
.option_list
:
31 long_option
= option
.get_opt_string().strip('-')
32 help_msg
= shell_quote([option
.help])
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
)