Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/scripts/completion_fish.py
5457 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License version 2 as
6
# published by the Free Software Foundation.
7
8
"""Generate fish completion script from gallery-dl's argument parser"""
9
10
import util
11
from gallery_dl import option
12
13
14
TEMPLATE = """complete -c gallery-dl -x
15
%(opts)s
16
"""
17
18
opts = []
19
for action in option.build_parser()._actions:
20
if not action.option_strings:
21
continue
22
23
opt = "complete -c gallery-dl"
24
25
if action.metavar:
26
if action.metavar == "FILE":
27
opt += " -r -F"
28
elif action.metavar == "PATH":
29
opt += " -x -a '(__fish_complete_directories)'"
30
else:
31
opt += " -x"
32
33
for optstr in action.option_strings:
34
if optstr.startswith("--"):
35
opt += " -l '" + optstr[2:] + "'"
36
else:
37
opt += " -s '" + optstr[1:] + "'"
38
39
opt += " -d '" + action.help.replace("'", '"') + "'"
40
41
opts.append(opt)
42
43
PATH = util.path("data/completion/gallery-dl.fish")
44
with util.lazy(PATH) as fp:
45
fp.write(TEMPLATE % {"opts": "\n".join(opts)})
46
47