Skip to content

Commit bac976b

Browse files
improved katacoda runner for parsing input parameter
1 parent 5048a6b commit bac976b

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

engine/runner.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,13 @@ export abstract class Runner {
109109
fs.mkdirSync(path, { recursive: true });
110110
return path;
111111
}
112+
113+
protected parseInputParameters(parameterString: string) {
114+
let regex = /(((?<array>\[[^\]]+\])|(?<string>[^[,]+))\s*,?\s*)/mg;
115+
let parameters = [];
116+
for (let matches = regex.exec(parameterString); matches != null; matches = regex.exec(parameterString)) {
117+
parameters.push(matches[2]);
118+
}
119+
return parameters;
120+
}
112121
}

playbooks/cobigen-cli/index.asciidoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Now, you have to download cobigen
1919
installCobiGen()
2020
--
2121

22-
The CobiGen plugin for VS Code is already installed. You can use it right away.
22+
====
23+
The CobiGen plugin for VS Code is already installed. We will use it to generate code from one single java class based on existing templates.
2324
[step]
2425
--
25-
cobiGenJava(Test.java,[1 2 3 4])
26-
--
26+
cobiGenJava(Test.java,[1,2,3,4])
27+
--
28+
====

runners/katacoda/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ export class Katacoda extends Runner {
6666
}
6767

6868
runInstallDevonfwIde(step: Step, command: Command): RunResult {
69-
let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim();
69+
let params = this.parseInputParameters(command.parameters);
70+
let tools = params[0].replace(/\[/, "").replace(/\]/g, "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim();
7071

7172
// create script to download devonfw ide settings
72-
this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: params, cloneDir: "/root/devonfw-settings/"});
73+
this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: tools, cloneDir: "/root/devonfw-settings/"});
7374

7475
// add the script to the setup scripts for executing it at the beginning of the tutorial
7576
this.setupScripts.push({
@@ -95,8 +96,8 @@ export class Katacoda extends Runner {
9596
}
9697

9798
runCobiGenJava(step: Step, command: Command): RunResult {
98-
let params = command.parameters.split(",");
99-
let cobiGenTemplates = params[1].replace(/\[/, "").replace("\]", "").replace(/ /g, ",");
99+
let params = this.parseInputParameters(command.parameters)
100+
let cobiGenTemplates = params[1].replace(/\[/, "").replace(/\]/g, "");
100101

101102
this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" });
102103
this.setupScripts.push({

runners/katacoda/templates/cobiGenJava.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ A terminal will open on the bottom of the IDE and CobiGen CLI will start.
1111

1212
You can choose the templates CobiGen should use by entering the numbers.
1313

14-
`<%= cobiGenTemplates; %>`{{execute}}
14+
`<%= cobiGenTemplates; %>`{{execute}}
15+
16+
<%= textAfter; %>

0 commit comments

Comments
 (0)