]>
jfr.im git - yt-dlp.git/blob - devscripts/fish-completion.py
6 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from yt_dlp
.utils
import shell_quote
11 FISH_COMPLETION_FILE
= 'completions/fish/yt-dlp.fish'
12 FISH_COMPLETION_TEMPLATE
= 'devscripts/fish-completion.in'
15 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
16 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
18 # Options that need a file parameter
19 'download-archive': ['--require-parameter'],
20 'cookies': ['--require-parameter'],
21 'load-info': ['--require-parameter'],
22 '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 complete_cmd
= ['complete', '--command', 'yt-dlp', '--long-option', long_option
]
33 if option
._short
_opts
:
34 complete_cmd
+= ['--short-option', option
._short
_opts
[0].strip('-')]
35 if option
.help != optparse
.SUPPRESS_HELP
:
36 complete_cmd
+= ['--description', option
.help]
37 complete_cmd
.extend(EXTRA_ARGS
.get(long_option
, []))
38 commands
.append(shell_quote(complete_cmd
))
40 with open(FISH_COMPLETION_TEMPLATE
) as f
:
42 filled_template
= template
.replace('{{commands}}', '\n'.join(commands
))
43 with open(FISH_COMPLETION_FILE
, 'w') as f
:
44 f
.write(filled_template
)
47 parser
= yt_dlp
.parseOpts(ignore_config_files
=True)[0]
48 build_completion(parser
)