@@ -24,6 +24,35 @@ def getHelpTxt(command=None):
24
24
out , err = p .communicate ()
25
25
return out
26
26
27
+ def getTargetCode ():
28
+ txt = ''
29
+ with open ("templates/target.tmplt" ) as fp :
30
+ txt = fp .read ()
31
+ return txt
32
+
33
+ def getToolchainCode ():
34
+ txt = ''
35
+ with open ("templates/toolchain.tmplt" ) as fp :
36
+ txt = fp .read ()
37
+ return txt
38
+
39
+ def getSCMCode ():
40
+ txt = ''
41
+ with open ("templates/scm.tmplt" ) as fp :
42
+ txt = fp .read ()
43
+ return txt
44
+
45
+ def getIDECode ():
46
+ txt = ''
47
+ with open ("templates/ide.tmplt" ) as fp :
48
+ txt = fp .read ()
49
+ return txt
50
+
51
+ def getProtocolCode ():
52
+ txt = ''
53
+ with open ("templates/protocol.tmplt" ) as fp :
54
+ txt = fp .read ()
55
+ return txt
27
56
28
57
def parseCommands ():
29
58
commands = defaultdict (defaultdict )
@@ -42,6 +71,8 @@ def parseCommands():
42
71
commands [g ["command" ]]["DASH_COMMANDS" ] = []
43
72
commands [g ["command" ]]["COMMAND" ] = g ["command" ]
44
73
74
+ commands [g ["command" ]]["HAVE_PREV" ] = {"PREV_CASE" : []}
75
+
45
76
# Main function generation
46
77
commands ["COMMAND" ].append ({"name" : g ["command" ]})
47
78
@@ -50,7 +81,6 @@ def parseCommands():
50
81
if commandKey == "COMMAND" :
51
82
continue
52
83
53
- command = commands [commandKey ]
54
84
helpTxt = getHelpTxt (commandKey )
55
85
for line in helpTxt .split ('\n ' ):
56
86
match = re .search (subcommandRegex , line )
@@ -90,12 +120,40 @@ def parseCommands():
90
120
if m :
91
121
commands [commandKey ]["DASH_COMMANDS" ].append (
92
122
{"name" : command1 })
123
+ else :
124
+ command1 = ""
93
125
94
126
if command2 :
95
127
m = re .match ("^-[a-zA-Z]{1,2}" , command2 )
96
128
if m :
97
129
commands [commandKey ]["DASH_COMMANDS" ].append (
98
130
{"name" : command2 })
131
+ else :
132
+ command2 = ""
133
+
134
+ # Adding the dependent command handlers
135
+ if "target" in command1 or "target" in command2 :
136
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : "|" .join (filter (None , [command1 , command2 ])), "code" : getTargetCode ()})
137
+
138
+ if "toolchain" in command1 or "toolchain" in command2 :
139
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : "|" .join (filter (None , [command1 , command2 ])), "code" : getToolchainCode ()})
140
+
141
+
142
+ if "--ide" in command1 or "--ide" in command2 :
143
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : "|" .join (filter (None , [command1 , command2 ])), "code" : getIDECode ()})
144
+
145
+ if "scm" in command1 or "scm" in command2 :
146
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : "|" .join (filter (None , [command1 , command2 ])), "code" : getSCMCode ()})
147
+
148
+ if "protocol" in command1 or "protocol" in command2 :
149
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : "|" .join (filter (None , [command1 , command2 ])), "code" : getProtocolCode ()})
150
+
151
+ # Adding the dependent command handlers for target and toolchain
152
+ if "target" in commandKey :
153
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : commandKey , "code" : getTargetCode ()})
154
+
155
+ if "toolchain" in commandKey :
156
+ commands [commandKey ]["HAVE_PREV" ]["PREV_CASE" ].append ({"case" : commandKey , "code" : getToolchainCode ()})
99
157
100
158
return commands
101
159
@@ -117,11 +175,13 @@ def generateCompleters(commands):
117
175
tmplt = ""
118
176
txt = []
119
177
178
+ renderer = pystache .Renderer (escape = lambda u : u )
179
+
120
180
with open ("templates/command.tmplt" ) as fp :
121
181
tmplt = fp .read ()
122
182
123
183
for commandKey in commands :
124
- txt .append (pystache .render (tmplt , commands [commandKey ]))
184
+ txt .append (renderer .render (tmplt , commands [commandKey ]))
125
185
126
186
# if need to add hacks add them here
127
187
0 commit comments