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