[ie] Resolve `language` to ISO639-2 for ISM formats (#11359)
[yt-dlp3.git] / devscripts / bash-completion.py
blob3918ebde86de1649cdf2662871470b7d13a10443
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10 import yt_dlp
12 BASH_COMPLETION_FILE = 'completions/bash/yt-dlp'
13 BASH_COMPLETION_TEMPLATE = 'devscripts/bash-completion.in'
16 def build_completion(opt_parser):
17 opts_flag = []
18 for group in opt_parser.option_groups:
19 for option in group.option_list:
20 # for every long flag
21 opts_flag.append(option.get_opt_string())
22 with open(BASH_COMPLETION_TEMPLATE) as f:
23 template = f.read()
24 with open(BASH_COMPLETION_FILE, 'w') as f:
25 # just using the special char
26 filled_template = template.replace('{{flags}}', ' '.join(opts_flag))
27 f.write(filled_template)
30 parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
31 build_completion(parser)