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.
@@ -10,15 +10,12 @@ import {
10
10
  positionalRequired,
11
11
  positionalVariadics,
12
12
  runAndExit,
13
- typeConverted,
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: typeConverted(typeOneOf("STRING-ENUM", ["42", "43"]), {
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: typeString,
369
+ type: typeOneOf("STRING-ENUM", ["required1", "required1-bis"]),
340
370
  label: "REQUIRED1",
341
371
  description: "Required1 positional description",
342
372
  }),