Skip to content

Commit 4c1ffe8

Browse files
Merge pull request #298 from GuentherJulian/fix/katacodaExecuteCommand
fix for executeCommand katacoda template
2 parents e4f4aa7 + 920acd6 commit 4c1ffe8

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

runners/katacoda/index.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,30 +404,27 @@ export class Katacoda extends Runner {
404404

405405
runExecuteCommand(runCommand: RunCommand) : RunResult {
406406
let terminal = (runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].asynchronous)
407-
? this.getTerminal("executeCommand"+runCommand.stepIndex)
407+
? this.getTerminal("executeCommand" + runCommand.stepIndex)
408408
: undefined;
409-
410-
let filepath;
411-
let changeDir = false;
412-
if(runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].dir){
413-
filepath = runCommand.command.parameters[2].asynchronous
414-
? path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir).replace(/\\/g, "/")
415-
: runCommand.command.parameters[2].dir;
416-
changeDir = true;
417-
this.currentDir = filepath;
418-
}
419409

410+
let cdCommand: string;
411+
if(runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].dir) {
412+
cdCommand = terminal
413+
? this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir), terminal.terminalId, terminal.isRunning)
414+
: this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir));
415+
} else {
416+
cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY)));
417+
}
418+
420419
let bashCommand = {
421420
"name" : runCommand.command.parameters[1],
422-
"changeDir" : changeDir,
423-
"path" : filepath,
424421
"terminalId" : terminal ? terminal.terminalId : 1,
425422
"interrupt" : terminal ? terminal.isRunning : false,
426423
"args": (runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].args) ? runCommand.command.parameters[2].args.join(" ") : undefined
427424
}
428425

429426
this.pushStep(runCommand, "Executing the command "+ runCommand.command.parameters[1] , "step"+ runCommand.stepIndex + ".md");
430-
this.renderTemplate("executeCommand.md", this.outputPathTutorial + "step" + (runCommand.stepIndex) + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, bashCommand: bashCommand});
427+
this.renderTemplate("executeCommand.md", this.outputPathTutorial + "step" + (runCommand.stepIndex) + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, bashCommand: bashCommand });
431428
return null;
432429
}
433430

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<%= text; %>
22

3-
<% if(bashCommand.interrupt){%><% if(bashCommand.changeDir){%>We want to execute the command in a different directory so you have to change your current directory. Some command is already running in terminal <%= bashCommand.terminalId; %> to stop the execution just use this command
4-
`cd <%= bashCommand.path; %> `{{execute T<%= bashCommand.terminalId; %> interrupt}} <% }} else{%>
5-
<% if(bashCommand.changeDir){%>We want to execute the command in a different directory so you have to change your current directory.
6-
With the next command we also open a new terminal, so you have to execute the command twice
7-
`cd <%= bashCommand.path; %> `{{execute T<%= bashCommand.terminalId; %>}}. <% } %><% } %>
8-
9-
<% if(bashCommand.interrupt){ %><% if(bashCommand.changeDir){%>Run <%= bashCommand.name; %> with this bash-command.`<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %>}} <% } else{%> Some command is already running in terminal <%= bashCommand.terminalId; %>. Rerun the command to stop and relaunch it automatically. `<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %> interrupt }} <%} }else{ %>Run <%= bashCommand.name; %> with this bash-command.
10-
`<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %>}} <%} %>
3+
<%= cdCommand; %>
4+
5+
<% if(bashCommand.interrupt) { %>
6+
Some command is already running in terminal <%= bashCommand.terminalId; %>. Rerun the command to stop and relaunch it automatically. `<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %> interrupt }}
7+
<% } else { %>
8+
Run `<%= bashCommand.name; %>` with this command.
9+
`<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %>}}
10+
<% } %>
1111

1212
<%= textAfter; %>
1313

0 commit comments

Comments
 (0)