forked from AS-BIG-FEMALE/Docker.md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
85 lines (80 loc) · 1.89 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
#! /usr/bin/env -S deno -A
import args from "https://deno.land/x/args@1.0.2/wrapper.ts";
import {
EarlyExitFlag,
BinaryFlag,
PartialOption,
} from "https://deno.land/x/args@1.0.2/flag-types.ts";
import {
Text,
Integer,
} from "https://deno.land/x/args@1.0.2/value-types.ts";
import {
MAIN_COMMAND,
} from "https://deno.land/x/args@1.0.2/symbols.ts";
import run from "./run.ts";
const parser = args
.describe("Run deno test files on localhost")
.with(EarlyExitFlag("help", {
alias: ["?"],
describe: "Show help",
exit() {
console.log("USAGE:");
console.log(" deno -A cli.ts [options] ...files");
console.log(parser.help());
return Deno.exit(0);
},
}))
.with(PartialOption("dir", {
alias: ["d"],
describe: "Target directory",
type: Text,
default: ".",
}))
.with(PartialOption("port", {
alias: ["p"],
describe: "Port to use",
type: Integer,
default: 4321n,
}))
.with(PartialOption("hostname", {
alias: ["h"],
describe: "Hostname to use",
type: Text,
default: "0.0.0.0",
}))
.with(BinaryFlag("cors", {
describe: "Enable Cross-Origin Resource Sharing",
}))
.with(PartialOption("deno", {
describe: "Deno command",
type: Text,
default: "deno",
}));
const parserRes = parser.parse(Deno.args);
if (parserRes.tag !== MAIN_COMMAND) {
console.error(parserRes.error.toString());
throw Deno.exit(1);
}
if (parserRes.remaining().rawFlags().length) {
console.error("Unknown flags:", ...parserRes.remaining().rawFlags());
throw Deno.exit(1);
}
const {
dir,
hostname,
port,
cors,
deno,
} = parserRes.value;
const testFiles = parserRes.remaining().rawValues();
Deno.chdir(dir);
const { code, signal } = await run({
list: testFiles.length ? testFiles : undefined,
hostname,
port: Number(port),
deno,
cors,
});
if (signal) console.error("SIGNAL", signal);
throw Deno.exit(code);