]> jfr.im git - yt-dlp.git/blame - devscripts/fish-completion.py
[cleanup] Delete unused extractors
[yt-dlp.git] / devscripts / fish-completion.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
56d1912f
JMF
2import optparse
3import os
56d1912f
JMF
4import sys
5
e5a998f3 6sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7
7a5c1cfe
P
8import yt_dlp
9from yt_dlp.utils import shell_quote
56d1912f 10
359d6d86 11FISH_COMPLETION_FILE = 'completions/fish/yt-dlp.fish'
56d1912f
JMF
12FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
13
14EXTRA_ARGS = {
efe87a10 15 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
56d1912f
JMF
16 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
17
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'],
23}
24
5f6a1245 25
56d1912f
JMF
26def build_completion(opt_parser):
27 commands = []
28
29 for group in opt_parser.option_groups:
30 for option in group.option_list:
31 long_option = option.get_opt_string().strip('-')
7a5c1cfe 32 complete_cmd = ['complete', '--command', 'yt-dlp', '--long-option', long_option]
56d1912f
JMF
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))
39
40 with open(FISH_COMPLETION_TEMPLATE) as f:
41 template = f.read()
42 filled_template = template.replace('{{commands}}', '\n'.join(commands))
43 with open(FISH_COMPLETION_FILE, 'w') as f:
44 f.write(filled_template)
45
582be358 46
7a5c1cfe 47parser = yt_dlp.parseOpts()[0]
56d1912f 48build_completion(parser)