@@ -24,6 +24,35 @@ def getHelpTxt(command=None):
2424 out , err = p .communicate ()
2525 return out
2626
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
2756
2857def parseCommands ():
2958 commands = defaultdict (defaultdict )
@@ -42,6 +71,8 @@ def parseCommands():
4271 commands [g ["command" ]]["DASH_COMMANDS" ] = []
4372 commands [g ["command" ]]["COMMAND" ] = g ["command" ]
4473
74+ commands [g ["command" ]]["HAVE_PREV" ] = {"PREV_CASE" : []}
75+
4576 # Main function generation
4677 commands ["COMMAND" ].append ({"name" : g ["command" ]})
4778
@@ -50,7 +81,6 @@ def parseCommands():
5081 if commandKey == "COMMAND" :
5182 continue
5283
53- command = commands [commandKey ]
5484 helpTxt = getHelpTxt (commandKey )
5585 for line in helpTxt .split ('\n ' ):
5686 match = re .search (subcommandRegex , line )
@@ -90,12 +120,40 @@ def parseCommands():
90120 if m :
91121 commands [commandKey ]["DASH_COMMANDS" ].append (
92122 {"name" : command1 })
123+ else :
124+ command1 = ""
93125
94126 if command2 :
95127 m = re .match ("^-[a-zA-Z]{1,2}" , command2 )
96128 if m :
97129 commands [commandKey ]["DASH_COMMANDS" ].append (
98130 {"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 ()})
99157
100158 return commands
101159
@@ -117,11 +175,13 @@ def generateCompleters(commands):
117175 tmplt = ""
118176 txt = []
119177
178+ renderer = pystache .Renderer (escape = lambda u : u )
179+
120180 with open ("templates/command.tmplt" ) as fp :
121181 tmplt = fp .read ()
122182
123183 for commandKey in commands :
124- txt .append (pystache .render (tmplt , commands [commandKey ]))
184+ txt .append (renderer .render (tmplt , commands [commandKey ]))
125185
126186 # if need to add hacks add them here
127187
0 commit comments