]>
jfr.im git - yt-dlp.git/blob - devscripts/fish-completion.py
2 from __future__
import unicode_literals
6 from os
.path
import dirname
as dirn
9 sys
.path
.insert(0, dirn(dirn((os
.path
.abspath(__file__
)))))
11 from youtube_dlc
.utils
import shell_quote
13 FISH_COMPLETION_FILE
= 'youtube-dlc.fish'
14 FISH_COMPLETION_TEMPLATE
= 'devscripts/fish-completion.in'
17 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
18 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
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'],
28 def build_completion(opt_parser
):
31 for group
in opt_parser
.option_groups
:
32 for option
in group
.option_list
:
33 long_option
= option
.get_opt_string().strip('-')
34 complete_cmd
= ['complete', '--command', 'youtube-dlc', '--long-option', long_option
]
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
))
42 with open(FISH_COMPLETION_TEMPLATE
) as f
:
44 filled_template
= template
.replace('{{commands}}', '\n'.join(commands
))
45 with open(FISH_COMPLETION_FILE
, 'w') as f
:
46 f
.write(filled_template
)
49 parser
= youtube_dlc
.parseOpts()[0]
50 build_completion(parser
)