cli-kiss 0.2.2 → 0.2.3
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 +509 -820
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +3 -0
- package/docs/guide/01_getting_started.md +4 -4
- package/docs/guide/02_commands.md +5 -10
- package/docs/guide/03_options.md +4 -6
- package/docs/guide/04_positionals.md +6 -8
- package/docs/guide/05_types.md +8 -10
- package/docs/guide/06_run.md +3 -4
- package/docs/index.md +3 -3
- package/package.json +1 -1
- package/src/lib/Command.ts +178 -245
- package/src/lib/Operation.ts +60 -80
- package/src/lib/Option.ts +112 -123
- package/src/lib/Positional.ts +59 -92
- package/src/lib/Reader.ts +53 -78
- package/src/lib/Run.ts +39 -57
- package/src/lib/Type.ts +81 -141
- package/src/lib/Typo.ts +121 -164
- package/src/lib/Usage.ts +56 -18
- package/tests/unit.command.execute.ts +81 -69
- package/tests/unit.command.usage.ts +228 -107
- package/tests/unit.runner.cycle.ts +37 -7
|
@@ -10,15 +10,12 @@ import {
|
|
|
10
10
|
positionalRequired,
|
|
11
11
|
positionalVariadics,
|
|
12
12
|
runAndExit,
|
|
13
|
-
|
|
13
|
+
typeMapped,
|
|
14
14
|
typeOneOf,
|
|
15
15
|
typeString,
|
|
16
16
|
typeUrl,
|
|
17
17
|
} from "../src";
|
|
18
18
|
|
|
19
|
-
// TODO - unit test for chained commands
|
|
20
|
-
// TODO - unit test for errors styling
|
|
21
|
-
|
|
22
19
|
it("run", async () => {
|
|
23
20
|
const rootUsage = [
|
|
24
21
|
"Usage: my-cli <REQUIRED1> <SUBCOMMAND>",
|
|
@@ -218,7 +215,31 @@ it("run", async () => {
|
|
|
218
215
|
1,
|
|
219
216
|
);
|
|
220
217
|
|
|
221
|
-
// Test invalid positional type value
|
|
218
|
+
// Test invalid positional type value (should keep parsing best-effort even on invalid values)
|
|
219
|
+
await testCase(
|
|
220
|
+
["invalid"],
|
|
221
|
+
[],
|
|
222
|
+
[rootUsage, "Error: <SUBCOMMAND>: Is required, but was not provided"],
|
|
223
|
+
1,
|
|
224
|
+
);
|
|
225
|
+
await testCase(
|
|
226
|
+
["invalid", "subcommand"],
|
|
227
|
+
[],
|
|
228
|
+
[
|
|
229
|
+
subcommandUsage,
|
|
230
|
+
'Error: <REQUIRED1>: STRING-ENUM: Invalid value: "invalid" (expected one of: "required1" | "required1-bis")',
|
|
231
|
+
],
|
|
232
|
+
1,
|
|
233
|
+
);
|
|
234
|
+
await testCase(
|
|
235
|
+
["invalid", "subcommand", "required2"],
|
|
236
|
+
[],
|
|
237
|
+
[
|
|
238
|
+
subcommandUsage,
|
|
239
|
+
'Error: <REQUIRED1>: STRING-ENUM: Invalid value: "invalid" (expected one of: "required1" | "required1-bis")',
|
|
240
|
+
],
|
|
241
|
+
1,
|
|
242
|
+
);
|
|
222
243
|
await testCase(
|
|
223
244
|
["required1", "subcommand", "invalid"],
|
|
224
245
|
[],
|
|
@@ -228,6 +249,15 @@ it("run", async () => {
|
|
|
228
249
|
],
|
|
229
250
|
1,
|
|
230
251
|
);
|
|
252
|
+
await testCase(
|
|
253
|
+
["invalid", "subcommand", "invalid"],
|
|
254
|
+
[],
|
|
255
|
+
[
|
|
256
|
+
subcommandUsage,
|
|
257
|
+
'Error: <REQUIRED1>: STRING-ENUM: Invalid value: "invalid" (expected one of: "required1" | "required1-bis")',
|
|
258
|
+
],
|
|
259
|
+
1,
|
|
260
|
+
);
|
|
231
261
|
|
|
232
262
|
// Test root command option invalid values (must not block parsing)
|
|
233
263
|
await testCase(
|
|
@@ -326,7 +356,7 @@ async function testCase(
|
|
|
326
356
|
}),
|
|
327
357
|
optionSingleValue: optionSingleValue({
|
|
328
358
|
long: "single-value",
|
|
329
|
-
type:
|
|
359
|
+
type: typeMapped(typeOneOf("STRING-ENUM", ["42", "43"]), {
|
|
330
360
|
content: "NUMBER-ENUM",
|
|
331
361
|
decoder: (value) => Number(value),
|
|
332
362
|
}),
|
|
@@ -336,7 +366,7 @@ async function testCase(
|
|
|
336
366
|
},
|
|
337
367
|
positionals: [
|
|
338
368
|
positionalRequired({
|
|
339
|
-
type:
|
|
369
|
+
type: typeOneOf("STRING-ENUM", ["required1", "required1-bis"]),
|
|
340
370
|
label: "REQUIRED1",
|
|
341
371
|
description: "Required1 positional description",
|
|
342
372
|
}),
|