]> jfr.im git - yt-dlp.git/blame - devscripts/fish-completion.py
[youtube:live] Relax _VALID_URL (closes #11164)
[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__)))))
56d1912f
JMF
10import youtube_dl
11from youtube_dl.utils import shell_quote
12
13FISH_COMPLETION_FILE = 'youtube-dl.fish'
14FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
15
16EXTRA_ARGS = {
17 'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
18
19 # Options that need a file parameter
20 'download-archive': ['--require-parameter'],
21 'cookies': ['--require-parameter'],
22 'load-info': ['--require-parameter'],
23 'batch-file': ['--require-parameter'],
24}
25
5f6a1245 26
56d1912f
JMF
27def build_completion(opt_parser):
28 commands = []
29
30 for group in opt_parser.option_groups:
31 for option in group.option_list:
32 long_option = option.get_opt_string().strip('-')
56d1912f
JMF
33 complete_cmd = ['complete', '--command', 'youtube-dl', '--long-option', long_option]
34 if option._short_opts:
35 complete_cmd += ['--short-option', option._short_opts[0].strip('-')]
36 if option.help != optparse.SUPPRESS_HELP:
37 complete_cmd += ['--description', option.help]
38 complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
39 commands.append(shell_quote(complete_cmd))
40
41 with open(FISH_COMPLETION_TEMPLATE) as f:
42 template = f.read()
43 filled_template = template.replace('{{commands}}', '\n'.join(commands))
44 with open(FISH_COMPLETION_FILE, 'w') as f:
45 f.write(filled_template)
46
47parser = youtube_dl.parseOpts()[0]
48build_completion(parser)