Skip to content

Commit 4859c99

Browse files
Merge pull request devonfw-tutorials#126 from derochs/main
Add runDownloadFile function
2 parents f34adfd + a4b1fdc commit 4859c99

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

runners/katacoda/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ export class Katacoda extends Runner {
286286
return null;
287287
}
288288

289+
runDownloadFile(runCommand: RunCommand): RunResult {
290+
this.pushStep(runCommand, "Download a file", "step" + this.getStepsCount(runCommand) + ".md");
291+
292+
let downloadDir = this.getVariable(this.workspaceDirectory).replace(/\\/g, "/")
293+
if (runCommand.command.parameters.length == 3) {
294+
downloadDir = downloadDir.concat("/", runCommand.command.parameters[2])
295+
}
296+
this.renderTemplate("downloadFile.md", this.outputPathTutorial + "step" + this.stepsCount + ".md", {text: runCommand.text, textAfter: runCommand.textAfter, downloadURL: runCommand.command.parameters[0], downloadDir: downloadDir, downloadFile: runCommand.command.parameters[1]});
297+
return null;
298+
}
299+
289300
runNextKatacodaStep(runCommand: RunCommand): RunResult {
290301
let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md");
291302
fs.writeFileSync(tempFile, "");
@@ -403,4 +414,4 @@ export class Katacoda extends Runner {
403414
}
404415
}
405416

406-
}
417+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= text; %>
2+
3+
Create the directory <%= downloadDir %> if it doesn't exist.
4+
5+
`mkdir -p <%= downloadDir %>`{{execute T1}}
6+
7+
Download a file from '<%= downloadURL %>' and save it to the specified location '<%= downloadDir %>/<%= downloadFile %>'.
8+
9+
`wget -c '<%= downloadURL %>' -O <%= downloadDir %>/<%= downloadFile %>`{{execute T1}}
10+
11+
<%= textAfter; %>

0 commit comments

Comments
 (0)