diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index e459388b..05a04753 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -404,30 +404,27 @@ export class Katacoda extends Runner { runExecuteCommand(runCommand: RunCommand) : RunResult { let terminal = (runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].asynchronous) - ? this.getTerminal("executeCommand"+runCommand.stepIndex) + ? this.getTerminal("executeCommand" + runCommand.stepIndex) : undefined; - - let filepath; - let changeDir = false; - if(runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].dir){ - filepath = runCommand.command.parameters[2].asynchronous - ? path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir).replace(/\\/g, "/") - : runCommand.command.parameters[2].dir; - changeDir = true; - this.currentDir = filepath; - } + let cdCommand: string; + if(runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].dir) { + cdCommand = terminal + ? this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir), terminal.terminalId, terminal.isRunning) + : this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY), runCommand.command.parameters[2].dir)); + } else { + cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.WORKSPACE_DIRECTORY))); + } + let bashCommand = { "name" : runCommand.command.parameters[1], - "changeDir" : changeDir, - "path" : filepath, "terminalId" : terminal ? terminal.terminalId : 1, "interrupt" : terminal ? terminal.isRunning : false, "args": (runCommand.command.parameters.length > 2 && runCommand.command.parameters[2].args) ? runCommand.command.parameters[2].args.join(" ") : undefined } this.pushStep(runCommand, "Executing the command "+ runCommand.command.parameters[1] , "step"+ runCommand.stepIndex + ".md"); - this.renderTemplate("executeCommand.md", this.outputPathTutorial + "step" + (runCommand.stepIndex) + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, bashCommand: bashCommand}); + this.renderTemplate("executeCommand.md", this.outputPathTutorial + "step" + (runCommand.stepIndex) + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, bashCommand: bashCommand }); return null; } diff --git a/runners/katacoda/templates/executeCommand.md b/runners/katacoda/templates/executeCommand.md index 3731ff96..3fb165c1 100644 --- a/runners/katacoda/templates/executeCommand.md +++ b/runners/katacoda/templates/executeCommand.md @@ -1,13 +1,13 @@ <%= text; %> -<% 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 -`cd <%= bashCommand.path; %> `{{execute T<%= bashCommand.terminalId; %> interrupt}} <% }} else{%> -<% if(bashCommand.changeDir){%>We want to execute the command in a different directory so you have to change your current directory. -With the next command we also open a new terminal, so you have to execute the command twice -`cd <%= bashCommand.path; %> `{{execute T<%= bashCommand.terminalId; %>}}. <% } %><% } %> - -<% 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. -`<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %>}} <%} %> +<%= cdCommand; %> + +<% if(bashCommand.interrupt) { %> +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 command. +`<%= bashCommand.name; %> <%= bashCommand.args; %>`{{execute T<%= bashCommand.terminalId; %>}} +<% } %> <%= textAfter; %>