-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
40 lines (33 loc) · 864 Bytes
/
main.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
import { Input } from "@cliffy/prompt";
import { verbose } from "./src/log.ts";
import { lex } from "./src/parse.ts";
if (import.meta.main) {
while (true) {
const command = await Input.prompt({
message: Deno.cwd(),
pointer: "$",
prefix: "",
});
if (!command) {
verbose("Empty input");
continue;
}
const lexedCommand = lex(command);
const childProc = new Deno.Command(lexedCommand.command, {
args: lexedCommand.commandParts,
});
let stdout: Uint8Array | undefined;
try {
({ stdout } = await childProc.output());
} catch (err) {
verbose(err);
if ((err as { code?: string }).code === "ENOENT") {
console.error(`mysh: command not found: ${commandParts[0]}`);
}
}
if (!stdout) {
continue;
}
await Deno.stdout.write(stdout);
}
}