This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
executable file
·98 lines (83 loc) · 2.1 KB
/
gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/env python
from __future__ import print_function, with_statement
from jinja2 import Environment, FileSystemLoader
import re
import subprocess
env = Environment(loader=FileSystemLoader('.'))
rust_config = env.get_template('rustc.fish.template')
cargo_config = env.get_template('cargo.fish.template')
# Codegen
codegen_re = re.compile('(\s+)-C(?P<arg>.+)(\s+)--(\s+)(?P<desc>[^\n]+)')
codegen_out, _ = subprocess.Popen(
['rustc','-C', 'help'],
stdout=subprocess.PIPE).communicate()
codegens = []
for match in codegen_re.finditer(codegen_out):
arg = match.group('arg')
if '=' in arg:
arg = arg[:arg.index('=')+1]
codegens.append({
'arg': arg.strip(),
'desc': match.group('desc').strip()
})
# Warnings
warning_re = re.compile('(\s+)(?P<arg>.+)(\s+)(allow|warn|deny)(\s+){2}(?P<desc>[^\n]+)')
warning_out, _ = subprocess.Popen(
['rustc','-W', 'help'],
stdout=subprocess.PIPE).communicate()
warning_arguments = []
for match in warning_re.finditer(warning_out):
warning_arguments.append({
'arg': match.group('arg').strip(),
'desc': match.group('desc').strip()
})
warnings = []
warning_flags = [
{
'short': 'W',
'long': 'warn'
},
{
'short': 'A',
'long': 'allow'
},
{
'short': 'D',
'long': 'deny'
},
{
'short': 'F',
'long': 'forbid'
}
]
for flag in warning_flags:
for arg in warning_arguments:
warnings.append({
'short': flag['short'], 'long': flag['long'], 'arg': arg['arg'],
'desc': arg['desc']
})
# Internal debugging
debug_re = re.compile('(\s+)-Z(?P<arg>.+)(\s+)--(\s+)(?P<desc>[^\n]+)')
debug_out, _ = subprocess.Popen(
['rustc','-Z', 'help'],
stdout=subprocess.PIPE).communicate()
debugs = []
for match in debug_re.finditer(debug_out):
debugs.append({
'arg': match.group('arg').strip(),
'desc': match.group('desc').strip()
})
with open('rustc.fish', 'w') as handle:
handle.write(rust_config.render(
r='complete -c rustc',
codegens=codegens,
warnings=warnings,
debugs=debugs
))
handle.write('\n')
with open('cargo.fish', 'w') as handle:
handle.write(cargo_config.render(
c='complete -c cargo',
s='__fish_seen_subcommand_from'
))
handle.write('\n')