]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import os | |
5 | from os.path import dirname as dirn | |
6 | import sys | |
7 | ||
8 | sys.path.insert(0, dirn(dirn((os.path.abspath(__file__))))) | |
9 | import yt_dlp | |
10 | ||
11 | BASH_COMPLETION_FILE = "completions/bash/yt-dlp" | |
12 | BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in" | |
13 | ||
14 | ||
15 | def build_completion(opt_parser): | |
16 | opts_flag = [] | |
17 | for group in opt_parser.option_groups: | |
18 | for option in group.option_list: | |
19 | # for every long flag | |
20 | opts_flag.append(option.get_opt_string()) | |
21 | with open(BASH_COMPLETION_TEMPLATE) as f: | |
22 | template = f.read() | |
23 | with open(BASH_COMPLETION_FILE, "w") as f: | |
24 | # just using the special char | |
25 | filled_template = template.replace("{{flags}}", " ".join(opts_flag)) | |
26 | f.write(filled_template) | |
27 | ||
28 | ||
29 | parser = yt_dlp.parseOpts()[0] | |
30 | build_completion(parser) |