-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
36 lines (33 loc) · 711 Bytes
/
cli.ts
File metadata and controls
36 lines (33 loc) · 711 Bytes
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
import { executeFile } from "./command/executeFile.ts";
import { startRepl } from "./command/startRepl.ts";
if (Deno.args.length === 0) {
startRepl();
} else if (Deno.args.length === 1) {
const arg = Deno.args[0];
if (arg.startsWith("-")) {
showHelp();
} else {
try {
const file = await Deno.readTextFile(arg);
const exitCode = executeFile(file);
Deno.exit(exitCode);
} catch (err) {
if (!(err instanceof Error)) {
throw err;
}
console.error(`${err.name}: ${err.message}`);
Deno.exit(1);
}
}
} else {
showHelp();
}
function showHelp() {
console.log(`
Usage:
To open REPL:
$ lambda
To execute file:
$ lambda <file>
`);
}