Skip to content

Commit 08febbf

Browse files
committed
generator now works. need to remove mbed OS x from toolchain lists
1 parent 5e41043 commit 08febbf

File tree

7 files changed

+81
-10
lines changed

7 files changed

+81
-10
lines changed

tools/bash_completion/generator.py

+62-2
Original file line numberDiff line numberDiff line change
@@ -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

2857
def 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

tools/bash_completion/templates/command.tmplt

+11-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ __mbed_complete_{{COMMAND}}() {
2222
;;
2323
esac
2424

25-
# Right now prev is not supported
26-
#case "$prev" in
27-
# toolchain|-G|--global|-v|--verbose|-vv|--very_verbose)
28-
# declare TOOLCHAINS=$(mbed target --supported | head -n 2 | tail -n 1 | tr '|' '\n' | sed -n '/^ Target/!p' | sed -n '/^ mbed/!p')
29-
# __mbedcomp "${TOOLCHAINS}"
30-
# return
31-
# ;;
32-
#esac
25+
# Handle the dependent commands
26+
{{#HAVE_PREV}}
27+
case "$prev" in
28+
{{#PREV_CASE}}
29+
{{case}})
30+
{{code}}
31+
return
32+
;;
33+
{{/PREV_CASE}}
34+
esac
35+
{{/HAVE_PREV}}
3336

3437
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare IDES=$(mbed export --supported ides)
2+
__mbedcomp "${IDES}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__mbedcomp "https http ssh git"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__mbedcomp "bld git hg"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare TARGETS=$(mbed compile --supported targets)
2+
__mbedcomp "${TARGETS}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare TOOLCHAINS=$(mbed compile --supported toolchains)
2+
__mbedcomp "${TOOLCHAINS}"

0 commit comments

Comments
 (0)