cli-kiss 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +42 -30
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/Command.ts +22 -24
- package/src/lib/Execution.ts +8 -11
- package/src/lib/Grid.ts +6 -2
- package/src/lib/Run.ts +5 -6
- package/src/lib/Type.ts +27 -2
- package/src/lib/Typo.ts +16 -7
- package/src/lib/Usage.ts +63 -59
- package/tests/{unit.command.run.ts → unit.command.runArgv.ts} +14 -13
- package/tests/unit.command.usage.ts +77 -71
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
optionRepeatable,
|
|
12
12
|
optionSingleValue,
|
|
13
13
|
ReaderTokenizer,
|
|
14
|
+
typeCommaList,
|
|
15
|
+
typeCommaTuple,
|
|
14
16
|
typeNumber,
|
|
15
17
|
typeString,
|
|
16
18
|
} from "../src";
|
|
@@ -18,11 +20,8 @@ import { usageToPrintableLines } from "../src/lib/Usage";
|
|
|
18
20
|
|
|
19
21
|
const cmd = commandWithSubcommands<string, any, any>(
|
|
20
22
|
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"Root command description",
|
|
24
|
-
"Second line of root command description",
|
|
25
|
-
],
|
|
23
|
+
description: "Root command description",
|
|
24
|
+
details: ["Root command details", "Second line of root command details"],
|
|
26
25
|
},
|
|
27
26
|
execution(
|
|
28
27
|
{
|
|
@@ -40,11 +39,10 @@ const cmd = commandWithSubcommands<string, any, any>(
|
|
|
40
39
|
label: "COOL-STUFF",
|
|
41
40
|
description: "Root string-option description",
|
|
42
41
|
}),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
description: "Root number-option description",
|
|
42
|
+
complexOption: optionRepeatable({
|
|
43
|
+
long: "complex-option",
|
|
44
|
+
type: typeCommaTuple([typeNumber, typeCommaList(typeString)]),
|
|
45
|
+
description: "Root complex-option description",
|
|
48
46
|
}),
|
|
49
47
|
},
|
|
50
48
|
arguments: [
|
|
@@ -67,10 +65,10 @@ const cmd = commandWithSubcommands<string, any, any>(
|
|
|
67
65
|
{
|
|
68
66
|
sub1: command(
|
|
69
67
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"Subcommand 1
|
|
73
|
-
"Second line of subcommand 1
|
|
68
|
+
description: "Subcommand 1 description",
|
|
69
|
+
details: [
|
|
70
|
+
"Subcommand 1 details",
|
|
71
|
+
"Second line of subcommand 1 details",
|
|
74
72
|
],
|
|
75
73
|
},
|
|
76
74
|
execution(
|
|
@@ -91,10 +89,10 @@ const cmd = commandWithSubcommands<string, any, any>(
|
|
|
91
89
|
),
|
|
92
90
|
sub2: command(
|
|
93
91
|
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"Subcommand 2
|
|
97
|
-
"Second line of subcommand 2
|
|
92
|
+
description: "Subcommand 2 description",
|
|
93
|
+
details: [
|
|
94
|
+
"Subcommand 2 details",
|
|
95
|
+
"Second line of subcommand 2 details",
|
|
98
96
|
],
|
|
99
97
|
},
|
|
100
98
|
execution(
|
|
@@ -120,7 +118,7 @@ const cmd = commandWithSubcommands<string, any, any>(
|
|
|
120
118
|
default: () => "42",
|
|
121
119
|
}),
|
|
122
120
|
argumentVariadics({
|
|
123
|
-
label: "VARIADIC
|
|
121
|
+
label: "VARIADIC",
|
|
124
122
|
description: "Variadic positional arguments",
|
|
125
123
|
type: typeString,
|
|
126
124
|
}),
|
|
@@ -135,57 +133,58 @@ const cmd = commandWithSubcommands<string, any, any>(
|
|
|
135
133
|
);
|
|
136
134
|
|
|
137
135
|
it("run", async () => {
|
|
138
|
-
const usage1 = getUsage([], cmd);
|
|
136
|
+
const usage1 = await getUsage([], cmd);
|
|
137
|
+
// console.log(usage1.join("\n"));
|
|
139
138
|
expect(usage1).toStrictEqual([
|
|
139
|
+
"{Root command description}+",
|
|
140
|
+
"{Root command details}@brightBlack",
|
|
141
|
+
"{Second line of root command details}@brightBlack",
|
|
140
142
|
"",
|
|
141
|
-
"{
|
|
142
|
-
"{
|
|
143
|
-
"{Second line of root command description}@grey",
|
|
143
|
+
"{Usage:}@brightGreen+",
|
|
144
|
+
" {my-cli}@brightCyan+ {<POS-1>}@brightBlue {<POS-2>}@brightBlue {<SUBCOMMAND>}@brightCyan+",
|
|
144
145
|
"",
|
|
145
|
-
"{
|
|
146
|
+
"{Arguments:}@brightGreen+",
|
|
147
|
+
"{ }{<POS-1>}@brightBlue{ }{First positional argument}+",
|
|
148
|
+
"{ }{<POS-2>}@brightBlue{ }{Second positional argument}+",
|
|
146
149
|
"",
|
|
147
|
-
"{
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
+
"{Subcommands:}@brightGreen+",
|
|
151
|
+
"{ }{sub1}@brightCyan+{ }{Subcommand 1 description}+",
|
|
152
|
+
"{ }{sub2}@brightCyan+{ }{Subcommand 2 description}+",
|
|
150
153
|
"",
|
|
151
|
-
"{Options:}@
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"",
|
|
156
|
-
"{Subcommands:}@green+",
|
|
157
|
-
" {sub1}@cyan+ {Subcommand 1 title}+",
|
|
158
|
-
" {sub2}@cyan+ {Subcommand 2 title}+",
|
|
154
|
+
"{Options:}@brightGreen+",
|
|
155
|
+
"{ }{-b}@brightCyan+{, }{--boolean-flag}@brightCyan+ { }{Root boolean-flag description}+",
|
|
156
|
+
"{ }{-s}@brightCyan+{, }{--string-option }@brightCyan+{<COOL-STUFF>}@brightBlue { }{Root string-option description}+",
|
|
157
|
+
"{ } {--complex-option }@brightCyan+{<NUMBER,STRING[,STRING...]>}@brightBlue{ }{Root complex-option description}+",
|
|
159
158
|
"",
|
|
160
159
|
]);
|
|
161
160
|
|
|
162
|
-
const usage2 = getUsage(["50", "51", "sub1", "final"], cmd);
|
|
161
|
+
const usage2 = await getUsage(["50", "51", "sub1", "final"], cmd);
|
|
163
162
|
expect(usage2).toStrictEqual([
|
|
163
|
+
"{Subcommand 1 description}+",
|
|
164
|
+
"{Subcommand 1 details}@brightBlack",
|
|
165
|
+
"{Second line of subcommand 1 details}@brightBlack",
|
|
164
166
|
"",
|
|
165
|
-
"{
|
|
166
|
-
"{
|
|
167
|
-
"{Second line of subcommand 1 description}@grey",
|
|
168
|
-
"",
|
|
169
|
-
"{Usage:}@green+ {my-cli}@cyan+ {<POS-1>}@cyan {<POS-2>}@cyan {sub1}@cyan+ {<POS-STRING>}@cyan",
|
|
167
|
+
"{Usage:}@brightGreen+",
|
|
168
|
+
" {my-cli}@brightCyan+ {<POS-1>}@brightBlue {<POS-2>}@brightBlue {sub1}@brightCyan+ {<POS-STRING>}@brightBlue",
|
|
170
169
|
"",
|
|
171
|
-
"{Arguments:}@
|
|
172
|
-
"
|
|
173
|
-
"
|
|
174
|
-
"
|
|
170
|
+
"{Arguments:}@brightGreen+",
|
|
171
|
+
"{ }{<POS-1>}@brightBlue { }{First positional argument}+",
|
|
172
|
+
"{ }{<POS-2>}@brightBlue { }{Second positional argument}+",
|
|
173
|
+
"{ }{<POS-STRING>}@brightBlue{ }{Positional string argument}+",
|
|
175
174
|
"",
|
|
176
|
-
"{Options:}@
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
175
|
+
"{Options:}@brightGreen+",
|
|
176
|
+
"{ }{-b}@brightCyan+{, }{--boolean-flag}@brightCyan+ { }{Root boolean-flag description}+",
|
|
177
|
+
"{ }{-s}@brightCyan+{, }{--string-option }@brightCyan+{<COOL-STUFF>}@brightBlue { }{Root string-option description}+",
|
|
178
|
+
"{ } {--complex-option }@brightCyan+{<NUMBER,STRING[,STRING...]>}@brightBlue{ }{Root complex-option description}+",
|
|
180
179
|
"",
|
|
181
180
|
]);
|
|
182
181
|
|
|
183
|
-
const usage3 = getUsage(
|
|
182
|
+
const usage3 = await getUsage(
|
|
184
183
|
[
|
|
185
184
|
"40",
|
|
186
185
|
"41",
|
|
187
186
|
"sub2",
|
|
188
|
-
"--
|
|
187
|
+
"--complex-option=42,hello,world",
|
|
189
188
|
"--number-option",
|
|
190
189
|
"123",
|
|
191
190
|
"--number-option",
|
|
@@ -198,34 +197,41 @@ it("run", async () => {
|
|
|
198
197
|
cmd,
|
|
199
198
|
);
|
|
200
199
|
expect(usage3).toStrictEqual([
|
|
201
|
-
"",
|
|
202
|
-
"{Subcommand 2
|
|
203
|
-
"{
|
|
204
|
-
"
|
|
205
|
-
"",
|
|
206
|
-
"{
|
|
207
|
-
"",
|
|
208
|
-
"{Arguments:}@
|
|
209
|
-
"
|
|
210
|
-
"
|
|
211
|
-
"
|
|
212
|
-
"
|
|
213
|
-
"
|
|
214
|
-
"",
|
|
215
|
-
"{Options:}@
|
|
216
|
-
"
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
"
|
|
200
|
+
"{Subcommand 2 description}+",
|
|
201
|
+
"{Subcommand 2 details}@brightBlack",
|
|
202
|
+
"{Second line of subcommand 2 details}@brightBlack",
|
|
203
|
+
"",
|
|
204
|
+
"{Usage:}@brightGreen+",
|
|
205
|
+
" {my-cli}@brightCyan+ {<POS-1>}@brightBlue {<POS-2>}@brightBlue {sub2}@brightCyan+ {<POS-NUMBER>}@brightBlue {[OPT-POS]}@brightBlue {[VARIADIC...]}@brightBlue",
|
|
206
|
+
"",
|
|
207
|
+
"{Arguments:}@brightGreen+",
|
|
208
|
+
"{ }{<POS-1>}@brightBlue { }{First positional argument}+",
|
|
209
|
+
"{ }{<POS-2>}@brightBlue { }{Second positional argument}+",
|
|
210
|
+
"{ }{<POS-NUMBER>}@brightBlue { }{Positional number argument}+",
|
|
211
|
+
"{ }{[OPT-POS]}@brightBlue { }{Optional positional argument}+",
|
|
212
|
+
"{ }{[VARIADIC...]}@brightBlue{ }{Variadic positional arguments}+",
|
|
213
|
+
"",
|
|
214
|
+
"{Options:}@brightGreen+",
|
|
215
|
+
"{ }{-b}@brightCyan+{, }{--boolean-flag}@brightCyan+ { }{Root boolean-flag description}+",
|
|
216
|
+
"{ }{-s}@brightCyan+{, }{--string-option }@brightCyan+{<COOL-STUFF>}@brightBlue { }{Root string-option description}+",
|
|
217
|
+
"{ } {--complex-option }@brightCyan+{<NUMBER,STRING[,STRING...]>}@brightBlue{ }{Root complex-option description}+",
|
|
218
|
+
"{ } {--dudu }@brightCyan+{<STRING>}@brightBlue { }{Dudu option description}+",
|
|
220
219
|
"",
|
|
221
220
|
]);
|
|
222
221
|
});
|
|
223
222
|
|
|
224
|
-
function getUsage<Context, Result>(
|
|
223
|
+
async function getUsage<Context, Result>(
|
|
225
224
|
argv: Array<string>,
|
|
226
225
|
command: Command<Context, Result>,
|
|
227
226
|
) {
|
|
228
227
|
const commandRunner = command.prepareRunner(new ReaderTokenizer(argv));
|
|
228
|
+
/*
|
|
229
|
+
try {
|
|
230
|
+
console.log(await commandRunner.execute({} as Context));
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error("Error during execution:", error);
|
|
233
|
+
}
|
|
234
|
+
*/
|
|
229
235
|
return usageToPrintableLines({
|
|
230
236
|
cliName: "my-cli",
|
|
231
237
|
commandUsage: commandRunner.computeUsage(),
|