-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopt.ts
51 lines (41 loc) · 1.19 KB
/
opt.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
import { Command, Flag, Help, Name, Opt, Version } from "../mod.ts";
@Help("example of how to use `Opt`")
@Name("program")
@Version("0.0.0")
class Program extends Command {
@Flag({ about: "boolean option" })
flag = false;
@Opt({ about: "string option as default" })
str = "";
@Opt({ about: "number option", type: "number" })
num = 0;
@Opt({
about: "option that can be specified multiple times",
type: "string",
multiple: true,
})
multiple!: string[];
@Opt({ about: "enable short key", short: true })
short1 = "";
@Opt({ about: "specify short key", short: "S" })
short2 = "";
@Opt({
about: "disable long key (need `short` option)",
long: false,
short: "L",
})
long1 = "";
@Opt({ about: "specify long key", long: "long-key" })
long2 = "";
execute() {
console.log(`--flag = ${this.flag}`);
console.log(`--str = ${this.str}`);
console.log(`--num = ${this.num}`);
console.log(`--multiple = ${this.multiple}`);
console.log(`-s, --short1 = ${this.short1}`);
console.log(`-S, --short2 = ${this.short2}`);
console.log(`-L = ${this.long1}`);
console.log(`--long-key = ${this.long2}`);
}
}
await Program.run(Deno.args);