-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcli.ts
89 lines (76 loc) · 3.47 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import AddLanguageCommand from "./commands/add-language";
import BuildAndRunCommand from "./commands/build-and-run";
import ClearCacheCommand from "./commands/clear-cache";
import CompileCommand from "./commands/compile";
import LintCommand from "./commands/lint";
import TestCommand from "./commands/test";
import { Argument, Command } from "@commander-js/extra-typings";
import UpgradeLanguageCommand from "./commands/upgrade-language";
const program = new Command();
program.name("course-sdk").description("CLI to develop & test CodeCrafters challenges").version("0.2.0");
program
.command("compile")
.description("Compile starter code & solutions")
.addArgument(new Argument("[language]", "language to compile for. Example: 'go'").default("", "All languages"))
.action(async (languageFilter) => {
await new CompileCommand(languageFilter).run();
});
program
.command("lint")
.description("Lint starter code & solutions")
.action(async () => {
await new LintCommand().run();
});
program
.command("test")
.description("Test starter code & solutions")
.addArgument(new Argument("[language]", "language to test for. Example: 'go'. Use 'all' to test all languages").argRequired())
.option("--no-compile", "Disable compiling starter code & solutions before testing")
.action(async (languageFilter, options) => {
if (languageFilter === "all") {
languageFilter = "";
}
if (options.compile) {
console.log("Compiling... (use --no-compile to skip)");
await new CompileCommand(languageFilter).run();
} else {
console.log("Skipping compilation");
}
await new TestCommand(languageFilter).run();
});
program
.command("build-and-run", { hidden: true }) // Used for internal testing
.description(
'Build dockerfile for any language, then run a command and validate its output. Example: \'course-sdk build-and-run go "go version" stdout "go version"\'. This command will build the dockerfile for go, run "go version" and assert that the stdout stream contains "go version"'
)
.addArgument(new Argument("[language]", "language to test for. Example: 'go'. Use 'all' to test all languages").argRequired())
.addArgument(new Argument("[commandToExecute]", "command to execute. Example: 'go version'").argRequired())
.addArgument(new Argument("[outputStreamType]", "output stream type. Example: 'stdout', 'stderr'").argRequired())
.addArgument(new Argument("[expectedOutput]", "expected output. Example: 'go version'").argRequired())
.action(async (languageFilter, commandToExecute, outputStreamType, expectedOutput) => {
if (languageFilter === "all") {
languageFilter = "";
}
await new BuildAndRunCommand(languageFilter, commandToExecute, outputStreamType, expectedOutput).run();
});
program
.command("add-language")
.description("Add a language to this course")
.addArgument(new Argument("[language]", "language to add. Example: 'go'").argRequired())
.action(async (languageSlug) => {
await new AddLanguageCommand(languageSlug).run();
});
program
.command("upgrade-language")
.description("Upgrade a language that this course already supports")
.addArgument(new Argument("[language]", "language to upgrade. Example: 'go'").argRequired())
.action(async (languageSlug) => {
await new UpgradeLanguageCommand(languageSlug).run();
});
program
.command("clear-cache")
.description("Clear caches used by other commands")
.action(async () => {
await new ClearCacheCommand().run();
});
program.parse();