-
Notifications
You must be signed in to change notification settings - Fork 1
/
clite.ts
executable file
·103 lines (82 loc) · 2.01 KB
/
clite.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env -S deno run -A
import { alias, cliteRun, help } from "../../clite_parser.ts";
let ret;
@help("This tool is a little example")
class Tool {
@alias("r")
retry = 2;
@alias("n")
@help("no changes mode")
dryRun = false;
@help("web url")
webUrl = "none";
main() {
ret = {
command: "main",
options: { retry: this.retry, dryRun: this.dryRun, webUrl: this.webUrl },
};
}
@help("create and start")
up() {
ret = {
command: "up",
options: { retry: this.retry, dryRun: this.dryRun, webUrl: this.webUrl },
};
}
down(force: boolean, timeout: number) {
ret = {
command: "down",
options: { retry: this.retry, dryRun: this.dryRun, webUrl: this.webUrl },
cmdArgs: { force, timeout },
};
}
}
cliteRun(Tool);
console.log(ret);
/*
$ ./clite.ts --help
This tool is a little example
Usage: <Tool file> [Options] [--] [command [command args]]
Commands:
main [default]
up create and start
down <force> <timeout>
Options:
-h, --help Show this help [default: false]
-r, --retry [default: 2]
-n, --dry-run no changes mode [default: false]
--web-url web url [default: "none"]
$ ./clite.ts
{
command: "main",
options: { retry: 2, dryRun: false, webUrl: "none" }
}
$ ./clite.ts -r8 --dry-run --web-url=http
{
command: "main",
options: { retry: 8, dryRun: true, webUrl: "http" }
}
$ ./clite.ts down true 40
{
command: "down",
options: { retry: 2, dryRun: false, webUrl: "none" },
cmdArgs: { force: true, timeout: 40 }
}
$ ./clite.ts -r8 --dry-run --web-url=http down true 40
{
command: "down",
options: { retry: 8, dryRun: true, webUrl: "http" },
cmdArgs: { force: true, timeout: 40 }
}
$ ./clite.ts --unk
An error occurred ! The help :
...
The error :
error: Uncaught (in promise) Error: The option "unk" doesn't exist
$ ./clite.ts unk
An error occurred ! The help :
...
The error :
error: Uncaught (in promise) Error: The command "unk" doesn't exist
...
*/