]> jfr.im git - yt-dlp.git/blob - devscripts/bash-completion.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / devscripts / bash-completion.py
1 #!/usr/bin/env python3
2
3 # Allow direct execution
4 import os
5 import sys
6
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9
10 import yt_dlp
11
12 BASH_COMPLETION_FILE = 'completions/bash/yt-dlp'
13 BASH_COMPLETION_TEMPLATE = 'devscripts/bash-completion.in'
14
15
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)
28
29
30 parser = yt_dlp.parseOpts(ignore_config_files=True)[0]
31 build_completion(parser)