]> jfr.im git - yt-dlp.git/blame - devscripts/fish-completion.py
[ie/youtube] Fix comments extraction (#9775)
[yt-dlp.git] / devscripts / fish-completion.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
54007a45 2
3# Allow direct execution
56d1912f 4import os
56d1912f
JMF
5import sys
6
e5a998f3 7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
54007a45 9
10import optparse
11
7a5c1cfe
P
12import yt_dlp
13from yt_dlp.utils import shell_quote
56d1912f 14
359d6d86 15FISH_COMPLETION_FILE = 'completions/fish/yt-dlp.fish'
56d1912f
JMF
16FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
17
18EXTRA_ARGS = {
efe87a10 19 'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
56d1912f
JMF
20 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
21
22 # Options that need a file parameter
23 'download-archive': ['--require-parameter'],
24 'cookies': ['--require-parameter'],
25 'load-info': ['--require-parameter'],
26 'batch-file': ['--require-parameter'],
27}
28
5f6a1245 29
56d1912f
JMF
30def build_completion(opt_parser):
31 commands = []
32
33 for group in opt_parser.option_groups:
34 for option in group.option_list:
35 long_option = option.get_opt_string().strip('-')
7a5c1cfe 36 complete_cmd = ['complete', '--command', 'yt-dlp', '--long-option', long_option]
56d1912f
JMF
37 if option._short_opts:
38 complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
39 if option.help != optparse.SUPPRESS_HELP:
40 complete_cmd += ['--description', option.help]
41 complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
42 commands.append(shell_quote(complete_cmd))
43
44 with open(FISH_COMPLETION_TEMPLATE) as f:
45 template = f.read()
46 filled_template = template.replace('{{commands}}', '\n'.join(commands))
47 with open(FISH_COMPLETION_FILE, 'w') as f:
48 f.write(filled_template)
49
582be358 50
c1714454 51parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
56d1912f 52build_completion(parser)