@flowscripter/dynamic-cli-framework 1.2.1 → 1.3.0

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.
Files changed (166) hide show
  1. package/README/core-service-providers.md +2 -2
  2. package/README/development.md +3 -6
  3. package/README/implementation-details.md +17 -17
  4. package/README/key-concepts.md +17 -17
  5. package/README.md +4 -4
  6. package/bun.lock +0 -2
  7. package/index.ts +22 -30
  8. package/package.json +19 -19
  9. package/src/api/argument/Argument.ts +1 -1
  10. package/src/api/argument/ArgumentValueTypes.ts +3 -10
  11. package/src/api/argument/ComplexOption.ts +5 -9
  12. package/src/api/command/GlobalCommand.ts +1 -4
  13. package/src/api/service/core/ArgumentPrompterService.ts +1 -3
  14. package/src/api/service/core/AsciiBannerGeneratorService.ts +1 -4
  15. package/src/api/service/core/CompletionService.ts +2 -6
  16. package/src/api/service/core/ImagePrinterService.ts +1 -2
  17. package/src/api/service/core/KeyValueService.ts +1 -2
  18. package/src/api/service/core/PrettyPrinterService.ts +1 -4
  19. package/src/api/service/core/PrinterService.ts +8 -9
  20. package/src/api/service/core/PrompterService.ts +4 -11
  21. package/src/api/service/core/ShutdownService.ts +1 -2
  22. package/src/api/service/core/SyntaxHighlighterService.ts +1 -5
  23. package/src/api/service/core/Table.ts +7 -25
  24. package/src/api/service/core/TreePrinterService.ts +1 -2
  25. package/src/cli/BaseCLI.ts +17 -47
  26. package/src/cli/DefaultRuntimeCLI.ts +1 -4
  27. package/src/command/CompletionCommand.ts +19 -45
  28. package/src/command/MultiCommandCliHelpCommand.ts +45 -92
  29. package/src/command/SingleCommandCliHelpCommand.ts +17 -28
  30. package/src/command/UsageCommand.ts +6 -12
  31. package/src/command/VersionCommand.ts +2 -6
  32. package/src/launcher.ts +4 -2
  33. package/src/runtime/DefaultContext.ts +2 -5
  34. package/src/runtime/argument/ArgumentTypeGuards.ts +1 -3
  35. package/src/runtime/command/CommandTypeGuards.ts +5 -14
  36. package/src/runtime/command/CommandValidator.ts +56 -118
  37. package/src/runtime/parser.ts +13 -17
  38. package/src/runtime/registry/CommandRegistry.ts +2 -7
  39. package/src/runtime/registry/DefaultCommandRegistry.ts +32 -84
  40. package/src/runtime/registry/DefaultServiceProviderRegistry.ts +3 -9
  41. package/src/runtime/runner.ts +103 -142
  42. package/src/runtime/scanner.ts +28 -46
  43. package/src/runtime/values/ValuePopulationResult.ts +1 -2
  44. package/src/runtime/values/argumentValueMerge.ts +16 -28
  45. package/src/runtime/values/argumentValueValidation.ts +21 -67
  46. package/src/runtime/values/globalCommandValuePopulation.ts +9 -18
  47. package/src/runtime/values/subCommandValuePopulation.ts +42 -65
  48. package/src/service/argumentPrompter/ArgumentPrompterServiceProvider.ts +3 -10
  49. package/src/service/argumentPrompter/DefaultArgumentPrompterService.ts +22 -59
  50. package/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.ts +5 -14
  51. package/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts +59 -77
  52. package/src/service/banner/BannerServiceProvider.ts +13 -35
  53. package/src/service/banner/command/NoBannerCommand.ts +2 -8
  54. package/src/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.ts +5 -10
  55. package/src/service/completion/CompletionServiceProvider.ts +20 -48
  56. package/src/service/completion/DefaultCompletionService.ts +17 -56
  57. package/src/service/completion/shell/ShellHandler.ts +1 -3
  58. package/src/service/completion/shell/fish.ts +1 -1
  59. package/src/service/completion/shell/powershell.ts +2 -12
  60. package/src/service/completion/shell/zsh.ts +1 -1
  61. package/src/service/configuration/ConfigurationServiceProvider.ts +40 -133
  62. package/src/service/configuration/DefaultKeyValueService.ts +6 -20
  63. package/src/service/configuration/DefaultSecretService.ts +10 -14
  64. package/src/service/configuration/command/ConfigCommand.ts +1 -4
  65. package/src/service/configuration/command/DumpConfigCommand.ts +9 -21
  66. package/src/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.ts +5 -14
  67. package/src/service/dataDumpGenerator/DefaultDataDumpGeneratorService.ts +5 -12
  68. package/src/service/imagePrinter/DefaultImagePrinterService.ts +1 -5
  69. package/src/service/imagePrinter/ImagePrinterServiceProvider.ts +1 -4
  70. package/src/service/prettyPrinter/DefaultPrettyPrinterService.ts +4 -12
  71. package/src/service/prettyPrinter/PrettyPrinterServiceProvider.ts +3 -10
  72. package/src/service/printer/DefaultPrinterService.ts +20 -83
  73. package/src/service/printer/PrinterServiceProvider.ts +3 -11
  74. package/src/service/printer/command/DarkModeCommand.ts +3 -10
  75. package/src/service/printer/command/LogLevelCommand.ts +7 -26
  76. package/src/service/printer/command/NoColorCommand.ts +3 -10
  77. package/src/service/printer/command/NoHyperlinksCommand.ts +3 -10
  78. package/src/service/printer/terminal/Progress.ts +99 -90
  79. package/src/service/printer/terminal/Spinner.ts +7 -26
  80. package/src/service/prompter/DefaultPrompterService.ts +2 -6
  81. package/src/service/prompter/PrompterServiceProvider.ts +3 -11
  82. package/src/service/prompter/command/NoPromptCommand.ts +3 -10
  83. package/src/service/prompter/prompt/PromptContext.ts +5 -18
  84. package/src/service/prompter/prompt/promptMultiSelect.ts +6 -21
  85. package/src/service/prompter/prompt/promptOpenUrl.ts +7 -22
  86. package/src/service/prompter/prompt/promptSingleSelect.ts +6 -23
  87. package/src/service/prompter/prompt/promptText.ts +10 -27
  88. package/src/service/prompter/prompt/promptToggle.ts +8 -8
  89. package/src/service/shutdown/ShutdownServiceProvider.ts +3 -10
  90. package/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts +13 -26
  91. package/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.ts +8 -21
  92. package/src/service/tableGenerator/DefaultTableGeneratorService.ts +44 -68
  93. package/src/service/tableGenerator/TableGeneratorServiceProvider.ts +7 -16
  94. package/src/service/treePrinter/DefaultTreePrinterService.ts +2 -7
  95. package/src/service/treePrinter/TreePrinterServiceProvider.ts +4 -12
  96. package/src/terminal/ImageRenderer.ts +35 -54
  97. package/src/terminal/PngDecoder.ts +10 -19
  98. package/src/terminal/TtyStyler.ts +11 -9
  99. package/src/terminal/TtyTerminal.ts +2 -10
  100. package/src/terminal/supportsHyperlinks.ts +4 -10
  101. package/src/util/configHelper.ts +3 -10
  102. package/src/util/envVarHelper.ts +50 -88
  103. package/src/util/helpHelper.ts +123 -193
  104. package/src/util/logger.ts +12 -42
  105. package/src/util/runnerHelper.ts +20 -61
  106. package/tests/cli/BaseCLI.test.ts +23 -80
  107. package/tests/command/CompletionCommand.test.ts +1 -6
  108. package/tests/command/MultiCommandCliHelpCommand.test.ts +51 -205
  109. package/tests/command/SingleCommandCliHelpCommand.test.ts +21 -103
  110. package/tests/command/UsageCommand.test.ts +4 -10
  111. package/tests/fixtures/Command.ts +87 -68
  112. package/tests/fixtures/CommandRegistry.ts +1 -3
  113. package/tests/fixtures/Context.ts +3 -11
  114. package/tests/fixtures/ServiceProviderRegistry.ts +1 -1
  115. package/tests/fixtures/prettierPluginFoo.ts +1 -1
  116. package/tests/fixtures/util.ts +2 -8
  117. package/tests/runtime/argument/ArgumentTypeGuards.test.ts +1 -3
  118. package/tests/runtime/command/CommandValidator.test.ts +881 -604
  119. package/tests/runtime/parser.test.ts +222 -246
  120. package/tests/runtime/registry/DefaultCommandRegistry.test.ts +15 -37
  121. package/tests/runtime/registry/DefaultServiceProviderRegistry.test.ts +2 -8
  122. package/tests/runtime/runner.test.ts +231 -281
  123. package/tests/runtime/scanner.test.ts +277 -475
  124. package/tests/runtime/values/argumentValueMerge.test.ts +133 -81
  125. package/tests/runtime/values/argumentValueValidation.test.ts +444 -588
  126. package/tests/runtime/values/globalCommandValuePopulation.test.ts +71 -253
  127. package/tests/runtime/values/subCommandValuePopulation.test.ts +1342 -1570
  128. package/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.ts +3 -12
  129. package/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.ts +36 -45
  130. package/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.ts +2 -8
  131. package/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.ts +40 -62
  132. package/tests/service/banner/BannerServiceProvider.test.ts +5 -18
  133. package/tests/service/banner/command/NoBannerCommand.test.ts +1 -4
  134. package/tests/service/completion/CompletionServiceProvider.test.ts +145 -214
  135. package/tests/service/completion/DefaultCompletionService.test.ts +17 -79
  136. package/tests/service/completion/shell/fish.test.ts +1 -3
  137. package/tests/service/configuration/ConfigurationServiceProvider.test.ts +26 -75
  138. package/tests/service/configuration/DefaultKeyValueService.test.ts +9 -21
  139. package/tests/service/configuration/DefaultSecretService.test.ts +7 -15
  140. package/tests/service/configuration/command/DumpConfigCommand.test.ts +4 -13
  141. package/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.ts +6 -12
  142. package/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.ts +1 -10
  143. package/tests/service/imagePrinter/DefaultImagePrinterService.test.ts +5 -70
  144. package/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.ts +4 -11
  145. package/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.ts +2 -6
  146. package/tests/service/printer/DefaultPrinterService.test.ts +57 -255
  147. package/tests/service/printer/PrinterServiceProvider.test.ts +2 -8
  148. package/tests/service/printer/command/DarkModeCommand.test.ts +4 -12
  149. package/tests/service/printer/command/LogLevelCommand.test.ts +4 -17
  150. package/tests/service/printer/command/NoColorCommand.test.ts +4 -12
  151. package/tests/service/printer/command/NoHyperlinksCommand.test.ts +7 -21
  152. package/tests/service/printer/terminal/Progress.test.ts +1 -3
  153. package/tests/service/printer/terminal/Spinner.test.ts +2 -8
  154. package/tests/service/prompter/DefaultPrompterService.test.ts +52 -69
  155. package/tests/service/prompter/PrompterServiceProvider.test.ts +2 -8
  156. package/tests/service/shutdown/ShutdownServiceProvider.test.ts +1 -3
  157. package/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.ts +13 -99
  158. package/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.ts +2 -7
  159. package/tests/service/tableGenerator/DefaultTableGeneratorService.test.ts +12 -33
  160. package/tests/service/tableGenerator/TableGeneratorServiceProvider.test.ts +2 -2
  161. package/tests/service/treePrinter/DefaultTreePrinterService.test.ts +4 -6
  162. package/tests/service/treePrinter/TreePrinterServiceProvider.test.ts +4 -8
  163. package/tests/terminal/ImageRenderer.test.ts +2 -11
  164. package/tests/terminal/PngDecoder.test.ts +2 -6
  165. package/tests/util/configHelper.test.ts +55 -137
  166. package/tests/util/envVarHelper.test.ts +46 -110
@@ -4,10 +4,7 @@ import {
4
4
  validateOptionValue,
5
5
  validatePositionalValue,
6
6
  } from "../../../src/runtime/values/argumentValueValidation.ts";
7
- import {
8
- type InvalidArgument,
9
- InvalidArgumentReason,
10
- } from "../../../src/api/RunResult.ts";
7
+ import { type InvalidArgument, InvalidArgumentReason } from "../../../src/api/RunResult.ts";
11
8
  import { getGlobalCommandWithShortAlias } from "../../fixtures/Command.ts";
12
9
  import {
13
10
  ArgumentValueTypeName,
@@ -138,45 +135,45 @@ describe("argumentValueValidation tests", () => {
138
135
  name: "foo",
139
136
  type: ArgumentValueTypeName.NUMBER,
140
137
  };
141
- expect(
142
- validateOptionValue(option, "foo", invalidArguments),
143
- ).toBeUndefined();
144
- expect(invalidArguments).toEqual([{
145
- argument: option,
146
- name: "foo",
147
- value: "foo",
148
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
149
- }]);
138
+ expect(validateOptionValue(option, "foo", invalidArguments)).toBeUndefined();
139
+ expect(invalidArguments).toEqual([
140
+ {
141
+ argument: option,
142
+ name: "foo",
143
+ value: "foo",
144
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
145
+ },
146
+ ]);
150
147
 
151
148
  option = {
152
149
  name: "foo",
153
150
  type: ArgumentValueTypeName.BOOLEAN,
154
151
  };
155
152
  invalidArguments = [];
156
- expect(
157
- validateOptionValue(option, "foo", invalidArguments),
158
- ).toBeUndefined();
159
- expect(invalidArguments).toEqual([{
160
- argument: option,
161
- name: "foo",
162
- value: "foo",
163
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
164
- }]);
153
+ expect(validateOptionValue(option, "foo", invalidArguments)).toBeUndefined();
154
+ expect(invalidArguments).toEqual([
155
+ {
156
+ argument: option,
157
+ name: "foo",
158
+ value: "foo",
159
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
160
+ },
161
+ ]);
165
162
 
166
163
  option = {
167
164
  name: "foo",
168
165
  type: ArgumentValueTypeName.INTEGER,
169
166
  };
170
167
  invalidArguments = [];
171
- expect(
172
- validateOptionValue(option, "1.1", invalidArguments),
173
- ).toBeUndefined();
174
- expect(invalidArguments).toEqual([{
175
- argument: option,
176
- name: "foo",
177
- value: "1.1",
178
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
179
- }]);
168
+ expect(validateOptionValue(option, "1.1", invalidArguments)).toBeUndefined();
169
+ expect(invalidArguments).toEqual([
170
+ {
171
+ argument: option,
172
+ name: "foo",
173
+ value: "1.1",
174
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
175
+ },
176
+ ]);
180
177
  });
181
178
 
182
179
  test("Option array", () => {
@@ -186,14 +183,7 @@ describe("argumentValueValidation tests", () => {
186
183
  isArray: true,
187
184
  };
188
185
  const invalidArguments: Array<InvalidArgument> = [];
189
- expect(
190
- validateOptionValue(option, ["foo", "bar"], invalidArguments),
191
- ).toEqual(
192
- [
193
- "foo",
194
- "bar",
195
- ],
196
- );
186
+ expect(validateOptionValue(option, ["foo", "bar"], invalidArguments)).toEqual(["foo", "bar"]);
197
187
  expect(invalidArguments).toEqual([]);
198
188
 
199
189
  option = {
@@ -201,10 +191,7 @@ describe("argumentValueValidation tests", () => {
201
191
  type: ArgumentValueTypeName.NUMBER,
202
192
  isArray: true,
203
193
  };
204
- expect(validateOptionValue(option, ["1", "2"], invalidArguments)).toEqual([
205
- 1,
206
- 2,
207
- ]);
194
+ expect(validateOptionValue(option, ["1", "2"], invalidArguments)).toEqual([1, 2]);
208
195
  expect(invalidArguments).toEqual([]);
209
196
 
210
197
  option = {
@@ -212,26 +199,22 @@ describe("argumentValueValidation tests", () => {
212
199
  type: ArgumentValueTypeName.BOOLEAN,
213
200
  isArray: true,
214
201
  };
215
- expect(
216
- validateOptionValue(option, ["true", "false"], invalidArguments),
217
- ).toEqual(
218
- [true, false],
219
- );
202
+ expect(validateOptionValue(option, ["true", "false"], invalidArguments)).toEqual([true, false]);
220
203
  expect(invalidArguments).toEqual([]);
221
204
 
222
205
  option = {
223
206
  name: "foo",
224
207
  type: ArgumentValueTypeName.STRING,
225
208
  };
226
- expect(
227
- validateOptionValue(option, ["true", "false"], invalidArguments),
228
- ).toBeUndefined();
229
- expect(invalidArguments).toEqual([{
230
- argument: option,
231
- name: "foo",
232
- value: ["true", "false"],
233
- reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
234
- }]);
209
+ expect(validateOptionValue(option, ["true", "false"], invalidArguments)).toBeUndefined();
210
+ expect(invalidArguments).toEqual([
211
+ {
212
+ argument: option,
213
+ name: "foo",
214
+ value: ["true", "false"],
215
+ reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
216
+ },
217
+ ]);
235
218
  });
236
219
 
237
220
  test("Optional option", () => {
@@ -241,9 +224,7 @@ describe("argumentValueValidation tests", () => {
241
224
  isOptional: true,
242
225
  };
243
226
  let invalidArguments: Array<InvalidArgument> = [];
244
- expect(
245
- validateOptionValue(option, undefined, invalidArguments),
246
- ).toBeUndefined();
227
+ expect(validateOptionValue(option, undefined, invalidArguments)).toBeUndefined();
247
228
  expect(invalidArguments).toEqual([]);
248
229
 
249
230
  option = {
@@ -252,23 +233,21 @@ describe("argumentValueValidation tests", () => {
252
233
  isArray: true,
253
234
  isOptional: true,
254
235
  };
255
- expect(
256
- validateOptionValue(option, undefined, invalidArguments),
257
- ).toBeUndefined();
236
+ expect(validateOptionValue(option, undefined, invalidArguments)).toBeUndefined();
258
237
  expect(invalidArguments).toEqual([]);
259
238
 
260
239
  option = {
261
240
  name: "foo",
262
241
  type: ArgumentValueTypeName.STRING,
263
242
  };
264
- expect(
265
- validateOptionValue(option, undefined, invalidArguments),
266
- ).toBeUndefined();
267
- expect(invalidArguments).toEqual([{
268
- argument: option,
269
- name: "foo",
270
- reason: InvalidArgumentReason.MISSING_VALUE,
271
- }]);
243
+ expect(validateOptionValue(option, undefined, invalidArguments)).toBeUndefined();
244
+ expect(invalidArguments).toEqual([
245
+ {
246
+ argument: option,
247
+ name: "foo",
248
+ reason: InvalidArgumentReason.MISSING_VALUE,
249
+ },
250
+ ]);
272
251
 
273
252
  option = {
274
253
  name: "foo",
@@ -276,14 +255,14 @@ describe("argumentValueValidation tests", () => {
276
255
  isArray: true,
277
256
  };
278
257
  invalidArguments = [];
279
- expect(
280
- validateOptionValue(option, undefined, invalidArguments),
281
- ).toBeUndefined();
282
- expect(invalidArguments).toEqual([{
283
- argument: option,
284
- name: "foo",
285
- reason: InvalidArgumentReason.MISSING_VALUE,
286
- }]);
258
+ expect(validateOptionValue(option, undefined, invalidArguments)).toBeUndefined();
259
+ expect(invalidArguments).toEqual([
260
+ {
261
+ argument: option,
262
+ name: "foo",
263
+ reason: InvalidArgumentReason.MISSING_VALUE,
264
+ },
265
+ ]);
287
266
  });
288
267
 
289
268
  test("Invalid option argument value - not an allowable value", () => {
@@ -301,15 +280,15 @@ describe("argumentValueValidation tests", () => {
301
280
  type: ArgumentValueTypeName.STRING,
302
281
  allowableValues: ["bar", "two"],
303
282
  };
304
- expect(
305
- validateOptionValue(option, "goo", invalidArguments),
306
- ).toBeUndefined();
307
- expect(invalidArguments).toEqual([{
308
- argument: option,
309
- name: "foo",
310
- value: "goo",
311
- reason: InvalidArgumentReason.ILLEGAL_VALUE,
312
- }]);
283
+ expect(validateOptionValue(option, "goo", invalidArguments)).toBeUndefined();
284
+ expect(invalidArguments).toEqual([
285
+ {
286
+ argument: option,
287
+ name: "foo",
288
+ value: "goo",
289
+ reason: InvalidArgumentReason.ILLEGAL_VALUE,
290
+ },
291
+ ]);
313
292
  });
314
293
 
315
294
  test("Invalid option argument value - not within range", () => {
@@ -322,15 +301,15 @@ describe("argumentValueValidation tests", () => {
322
301
  expect(validateOptionValue(option, "1", invalidArguments), "1");
323
302
  expect(invalidArguments).toEqual([]);
324
303
 
325
- expect(
326
- validateOptionValue(option, "0", invalidArguments),
327
- ).toBeUndefined();
328
- expect(invalidArguments).toEqual([{
329
- argument: option,
330
- name: "foo",
331
- value: "0",
332
- reason: InvalidArgumentReason.ILLEGAL_VALUE,
333
- }]);
304
+ expect(validateOptionValue(option, "0", invalidArguments)).toBeUndefined();
305
+ expect(invalidArguments).toEqual([
306
+ {
307
+ argument: option,
308
+ name: "foo",
309
+ value: "0",
310
+ reason: InvalidArgumentReason.ILLEGAL_VALUE,
311
+ },
312
+ ]);
334
313
  });
335
314
 
336
315
  test("Complex options", () => {
@@ -349,71 +328,67 @@ describe("argumentValueValidation tests", () => {
349
328
  ],
350
329
  };
351
330
  let invalidArguments: Array<InvalidArgument> = [];
352
- expect(
353
- validateOptionValue(option, { a: 1, b: 2 }, invalidArguments),
354
- ).toEqual(
355
- { a: 1, b: 2 },
356
- );
331
+ expect(validateOptionValue(option, { a: 1, b: 2 }, invalidArguments)).toEqual({ a: 1, b: 2 });
357
332
  expect(invalidArguments).toEqual([]);
358
333
 
359
334
  invalidArguments = [];
360
335
 
361
- expect(
362
- validateOptionValue(option, { a: "bar", b: 2 }, invalidArguments),
363
- ).toBeUndefined();
364
- expect(invalidArguments).toEqual([{
365
- argument: option.properties[0],
366
- name: "foo.a",
367
- value: "bar",
368
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
369
- }]);
336
+ expect(validateOptionValue(option, { a: "bar", b: 2 }, invalidArguments)).toBeUndefined();
337
+ expect(invalidArguments).toEqual([
338
+ {
339
+ argument: option.properties[0],
340
+ name: "foo.a",
341
+ value: "bar",
342
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
343
+ },
344
+ ]);
370
345
 
371
346
  invalidArguments = [];
372
347
 
373
- expect(
374
- validateOptionValue(option, { b: 2 }, invalidArguments),
375
- ).toBeUndefined();
376
- expect(invalidArguments).toEqual([{
377
- argument: option.properties[0],
378
- name: "foo.a",
379
- reason: InvalidArgumentReason.MISSING_VALUE,
380
- }]);
348
+ expect(validateOptionValue(option, { b: 2 }, invalidArguments)).toBeUndefined();
349
+ expect(invalidArguments).toEqual([
350
+ {
351
+ argument: option.properties[0],
352
+ name: "foo.a",
353
+ reason: InvalidArgumentReason.MISSING_VALUE,
354
+ },
355
+ ]);
381
356
 
382
357
  invalidArguments = [];
383
358
 
384
- expect(
385
- validateOptionValue(option, { a: [1, 2], b: 2 }, invalidArguments),
386
- ).toBeUndefined();
387
- expect(invalidArguments).toEqual([{
388
- argument: option.properties[0],
389
- name: "foo.a",
390
- value: [1, 2],
391
- reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
392
- }]);
359
+ expect(validateOptionValue(option, { a: [1, 2], b: 2 }, invalidArguments)).toBeUndefined();
360
+ expect(invalidArguments).toEqual([
361
+ {
362
+ argument: option.properties[0],
363
+ name: "foo.a",
364
+ value: [1, 2],
365
+ reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
366
+ },
367
+ ]);
393
368
 
394
369
  invalidArguments = [];
395
370
 
396
- expect(
397
- validateOptionValue(option, "bar", invalidArguments),
398
- ).toBeUndefined();
399
- expect(invalidArguments).toEqual([{
400
- argument: option,
401
- name: "foo",
402
- value: "bar",
403
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
404
- }]);
371
+ expect(validateOptionValue(option, "bar", invalidArguments)).toBeUndefined();
372
+ expect(invalidArguments).toEqual([
373
+ {
374
+ argument: option,
375
+ name: "foo",
376
+ value: "bar",
377
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
378
+ },
379
+ ]);
405
380
 
406
381
  invalidArguments = [];
407
382
 
408
- expect(
409
- validateOptionValue(option, { a: 1, b: { c: 3 } }, invalidArguments),
410
- ).toBeUndefined();
411
- expect(invalidArguments).toEqual([{
412
- argument: option.properties[1],
413
- name: "foo.b",
414
- value: { c: 3 },
415
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
416
- }]);
383
+ expect(validateOptionValue(option, { a: 1, b: { c: 3 } }, invalidArguments)).toBeUndefined();
384
+ expect(invalidArguments).toEqual([
385
+ {
386
+ argument: option.properties[1],
387
+ name: "foo.b",
388
+ value: { c: 3 },
389
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
390
+ },
391
+ ]);
417
392
  });
418
393
 
419
394
  test("Option array of complex options", () => {
@@ -433,22 +408,24 @@ describe("argumentValueValidation tests", () => {
433
408
  ],
434
409
  };
435
410
  let invalidArguments: Array<InvalidArgument> = [];
436
- expect(
437
- validateOptionValue(option, [{ a: 1, b: 2 }], invalidArguments),
438
- ).toEqual(
439
- [{ a: 1, b: 2 }],
440
- );
411
+ expect(validateOptionValue(option, [{ a: 1, b: 2 }], invalidArguments)).toEqual([
412
+ { a: 1, b: 2 },
413
+ ]);
441
414
  expect(invalidArguments).toEqual([]);
442
415
 
443
416
  expect(
444
417
  validateOptionValue(
445
418
  option,
446
- [{ a: 1, b: 2 }, { a: 3, b: 4 }],
419
+ [
420
+ { a: 1, b: 2 },
421
+ { a: 3, b: 4 },
422
+ ],
447
423
  invalidArguments,
448
424
  ),
449
- ).toEqual(
450
- [{ a: 1, b: 2 }, { a: 3, b: 4 }],
451
- );
425
+ ).toEqual([
426
+ { a: 1, b: 2 },
427
+ { a: 3, b: 4 },
428
+ ]);
452
429
  expect(invalidArguments).toEqual([]);
453
430
 
454
431
  invalidArguments = [];
@@ -456,42 +433,47 @@ describe("argumentValueValidation tests", () => {
456
433
  expect(
457
434
  validateOptionValue(
458
435
  option,
459
- [{ a: 1, b: 2 }, { a: "bar", b: 4 }],
436
+ [
437
+ { a: 1, b: 2 },
438
+ { a: "bar", b: 4 },
439
+ ],
460
440
  invalidArguments,
461
441
  ),
462
442
  ).toBeUndefined();
463
- expect(invalidArguments).toEqual([{
464
- argument: option.properties[0],
465
- name: "foo[1].a",
466
- value: "bar",
467
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
468
- }]);
443
+ expect(invalidArguments).toEqual([
444
+ {
445
+ argument: option.properties[0],
446
+ name: "foo[1].a",
447
+ value: "bar",
448
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
449
+ },
450
+ ]);
469
451
 
470
452
  invalidArguments = [];
471
453
 
472
454
  expect(
473
455
  validateOptionValue(option, [{ a: 1, b: 2 }, { b: 4 }], invalidArguments),
474
456
  ).toBeUndefined();
475
- expect(invalidArguments).toEqual([{
476
- argument: option.properties[0],
477
- name: "foo[1].a",
478
- reason: InvalidArgumentReason.MISSING_VALUE,
479
- }]);
457
+ expect(invalidArguments).toEqual([
458
+ {
459
+ argument: option.properties[0],
460
+ name: "foo[1].a",
461
+ reason: InvalidArgumentReason.MISSING_VALUE,
462
+ },
463
+ ]);
480
464
 
481
465
  invalidArguments = [];
482
466
 
483
467
  expect(
484
- validateOptionValue(
485
- option,
486
- [undefined, { a: 3, b: 4 }],
487
- invalidArguments,
488
- ),
468
+ validateOptionValue(option, [undefined, { a: 3, b: 4 }], invalidArguments),
489
469
  ).toBeUndefined();
490
- expect(invalidArguments).toEqual([{
491
- argument: option,
492
- name: "foo[0]",
493
- reason: InvalidArgumentReason.ILLEGAL_SPARSE_ARRAY,
494
- }]);
470
+ expect(invalidArguments).toEqual([
471
+ {
472
+ argument: option,
473
+ name: "foo[0]",
474
+ reason: InvalidArgumentReason.ILLEGAL_SPARSE_ARRAY,
475
+ },
476
+ ]);
495
477
  });
496
478
 
497
479
  test("Complex nested options", () => {
@@ -500,65 +482,62 @@ describe("argumentValueValidation tests", () => {
500
482
  shortAlias: "a",
501
483
  type: ComplexValueTypeName.COMPLEX,
502
484
  isArray: true,
503
- properties: [{
504
- name: "beta",
505
- shortAlias: "b",
506
- type: ComplexValueTypeName.COMPLEX,
507
- isArray: true,
508
- properties: [{
509
- name: "gamma",
510
- shortAlias: "g",
511
- type: ArgumentValueTypeName.STRING,
512
- }, {
513
- name: "delta",
514
- shortAlias: "d",
515
- type: ArgumentValueTypeName.NUMBER,
516
- isArray: true,
517
- }],
518
- }],
519
- };
520
- let invalidArguments: Array<InvalidArgument> = [];
521
- expect(
522
- validateOptionValue(option, [
523
- {
524
- beta: [
525
- {
526
- delta: [
527
- 1,
528
- ],
529
- gamma: "foo1",
530
- },
531
- {
532
- delta: [
533
- 3,
534
- 2,
535
- ],
536
- gamma: "foo2",
537
- },
538
- ],
539
- },
540
- ], invalidArguments),
541
- ).toEqual(
542
- [
485
+ properties: [
543
486
  {
544
- beta: [
487
+ name: "beta",
488
+ shortAlias: "b",
489
+ type: ComplexValueTypeName.COMPLEX,
490
+ isArray: true,
491
+ properties: [
545
492
  {
546
- delta: [
547
- 1,
548
- ],
549
- gamma: "foo1",
493
+ name: "gamma",
494
+ shortAlias: "g",
495
+ type: ArgumentValueTypeName.STRING,
550
496
  },
551
497
  {
552
- delta: [
553
- 3,
554
- 2,
555
- ],
556
- gamma: "foo2",
498
+ name: "delta",
499
+ shortAlias: "d",
500
+ type: ArgumentValueTypeName.NUMBER,
501
+ isArray: true,
557
502
  },
558
503
  ],
559
504
  },
560
505
  ],
561
- );
506
+ };
507
+ let invalidArguments: Array<InvalidArgument> = [];
508
+ expect(
509
+ validateOptionValue(
510
+ option,
511
+ [
512
+ {
513
+ beta: [
514
+ {
515
+ delta: [1],
516
+ gamma: "foo1",
517
+ },
518
+ {
519
+ delta: [3, 2],
520
+ gamma: "foo2",
521
+ },
522
+ ],
523
+ },
524
+ ],
525
+ invalidArguments,
526
+ ),
527
+ ).toEqual([
528
+ {
529
+ beta: [
530
+ {
531
+ delta: [1],
532
+ gamma: "foo1",
533
+ },
534
+ {
535
+ delta: [3, 2],
536
+ gamma: "foo2",
537
+ },
538
+ ],
539
+ },
540
+ ]);
562
541
  expect(invalidArguments).toEqual([]);
563
542
 
564
543
  invalidArguments = [];
@@ -574,12 +553,14 @@ describe("argumentValueValidation tests", () => {
574
553
  invalidArguments,
575
554
  ),
576
555
  ).toBeUndefined();
577
- expect(invalidArguments).toEqual([{
578
- argument: option.properties[0],
579
- name: "alpha[0].beta",
580
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
581
- value: 1,
582
- }]);
556
+ expect(invalidArguments).toEqual([
557
+ {
558
+ argument: option.properties[0],
559
+ name: "alpha[0].beta",
560
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
561
+ value: 1,
562
+ },
563
+ ]);
583
564
  });
584
565
 
585
566
  test("Complex sparse array options", () => {
@@ -588,42 +569,49 @@ describe("argumentValueValidation tests", () => {
588
569
  shortAlias: "a",
589
570
  type: ComplexValueTypeName.COMPLEX,
590
571
  isArray: true,
591
- properties: [{
592
- name: "beta",
593
- shortAlias: "b",
594
- type: ComplexValueTypeName.COMPLEX,
595
- isArray: true,
596
- properties: [{
597
- name: "gamma",
598
- shortAlias: "g",
599
- type: ArgumentValueTypeName.STRING,
600
- }, {
601
- name: "delta",
602
- shortAlias: "d",
603
- type: ArgumentValueTypeName.NUMBER,
604
- isArray: true,
605
- }],
606
- }],
607
- };
608
- const invalidArguments: Array<InvalidArgument> = [];
609
- const value: Array<PopulatedArgumentValues> = [{
610
- beta: [
611
- {},
572
+ properties: [
612
573
  {
613
- gamma: "foo1",
614
- delta: [3, 2],
574
+ name: "beta",
575
+ shortAlias: "b",
576
+ type: ComplexValueTypeName.COMPLEX,
577
+ isArray: true,
578
+ properties: [
579
+ {
580
+ name: "gamma",
581
+ shortAlias: "g",
582
+ type: ArgumentValueTypeName.STRING,
583
+ },
584
+ {
585
+ name: "delta",
586
+ shortAlias: "d",
587
+ type: ArgumentValueTypeName.NUMBER,
588
+ isArray: true,
589
+ },
590
+ ],
615
591
  },
616
592
  ],
617
- }];
618
-
619
- expect(
620
- validateOptionValue(option, value, invalidArguments),
621
- ).toBeUndefined();
622
- expect(invalidArguments).toEqual([{
623
- argument: (option.properties[0] as ComplexOption).properties[0],
624
- name: "alpha[0].beta[0].gamma",
625
- reason: 0,
626
- }]);
593
+ };
594
+ const invalidArguments: Array<InvalidArgument> = [];
595
+ const value: Array<PopulatedArgumentValues> = [
596
+ {
597
+ beta: [
598
+ {},
599
+ {
600
+ gamma: "foo1",
601
+ delta: [3, 2],
602
+ },
603
+ ],
604
+ },
605
+ ];
606
+
607
+ expect(validateOptionValue(option, value, invalidArguments)).toBeUndefined();
608
+ expect(invalidArguments).toEqual([
609
+ {
610
+ argument: (option.properties[0] as ComplexOption).properties[0],
611
+ name: "alpha[0].beta[0].gamma",
612
+ reason: 0,
613
+ },
614
+ ]);
627
615
  });
628
616
 
629
617
  test("Positional types", () => {
@@ -632,69 +620,58 @@ describe("argumentValueValidation tests", () => {
632
620
  type: ArgumentValueTypeName.STRING,
633
621
  };
634
622
  let invalidArguments: Array<InvalidArgument> = [];
635
- expect(
636
- validatePositionalValue(positional, "foo", invalidArguments),
637
- "foo",
638
- );
623
+ expect(validatePositionalValue(positional, "foo", invalidArguments), "foo");
639
624
  expect(invalidArguments).toEqual([]);
640
625
 
641
626
  positional = {
642
627
  name: "foo",
643
628
  type: ArgumentValueTypeName.NUMBER,
644
629
  };
645
- expect(validatePositionalValue(positional, "1", invalidArguments)).toEqual(
646
- 1,
647
- );
630
+ expect(validatePositionalValue(positional, "1", invalidArguments)).toEqual(1);
648
631
  expect(invalidArguments).toEqual([]);
649
632
 
650
633
  positional = {
651
634
  name: "foo",
652
635
  type: ArgumentValueTypeName.BOOLEAN,
653
636
  };
654
- expect(
655
- validatePositionalValue(positional, "true", invalidArguments),
656
- ).toBeTrue();
637
+ expect(validatePositionalValue(positional, "true", invalidArguments)).toBeTrue();
657
638
  expect(invalidArguments).toEqual([]);
658
639
 
659
640
  positional = {
660
641
  name: "foo",
661
642
  type: ArgumentValueTypeName.STRING,
662
643
  };
663
- expect(
664
- validatePositionalValue(positional, "1", invalidArguments),
665
- ).toEqual(
666
- "1",
667
- );
644
+ expect(validatePositionalValue(positional, "1", invalidArguments)).toEqual("1");
668
645
  expect(invalidArguments).toEqual([]);
669
646
 
670
647
  positional = {
671
648
  name: "foo",
672
649
  type: ArgumentValueTypeName.NUMBER,
673
650
  };
674
- expect(
675
- validatePositionalValue(positional, "foo", invalidArguments),
676
- ).toBeUndefined();
677
- expect(invalidArguments).toEqual([{
678
- argument: positional,
679
- name: "foo",
680
- value: "foo",
681
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
682
- }]);
651
+ expect(validatePositionalValue(positional, "foo", invalidArguments)).toBeUndefined();
652
+ expect(invalidArguments).toEqual([
653
+ {
654
+ argument: positional,
655
+ name: "foo",
656
+ value: "foo",
657
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
658
+ },
659
+ ]);
683
660
 
684
661
  positional = {
685
662
  name: "foo",
686
663
  type: ArgumentValueTypeName.BOOLEAN,
687
664
  };
688
665
  invalidArguments = [];
689
- expect(
690
- validatePositionalValue(positional, "foo", invalidArguments),
691
- ).toBeUndefined();
692
- expect(invalidArguments).toEqual([{
693
- argument: positional,
694
- name: "foo",
695
- value: "foo",
696
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
697
- }]);
666
+ expect(validatePositionalValue(positional, "foo", invalidArguments)).toBeUndefined();
667
+ expect(invalidArguments).toEqual([
668
+ {
669
+ argument: positional,
670
+ name: "foo",
671
+ value: "foo",
672
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
673
+ },
674
+ ]);
698
675
  });
699
676
 
700
677
  test("Positional varargs multiple", () => {
@@ -704,11 +681,10 @@ describe("argumentValueValidation tests", () => {
704
681
  isVarargMultiple: true,
705
682
  };
706
683
  const invalidArguments: Array<InvalidArgument> = [];
707
- expect(
708
- validatePositionalValue(positional, ["foo", "bar"], invalidArguments),
709
- ).toEqual(
710
- ["foo", "bar"],
711
- );
684
+ expect(validatePositionalValue(positional, ["foo", "bar"], invalidArguments)).toEqual([
685
+ "foo",
686
+ "bar",
687
+ ]);
712
688
  expect(invalidArguments).toEqual([]);
713
689
 
714
690
  positional = {
@@ -716,11 +692,7 @@ describe("argumentValueValidation tests", () => {
716
692
  type: ArgumentValueTypeName.NUMBER,
717
693
  isVarargMultiple: true,
718
694
  };
719
- expect(
720
- validatePositionalValue(positional, ["1", "2"], invalidArguments),
721
- ).toEqual(
722
- [1, 2],
723
- );
695
+ expect(validatePositionalValue(positional, ["1", "2"], invalidArguments)).toEqual([1, 2]);
724
696
  expect(invalidArguments).toEqual([]);
725
697
 
726
698
  positional = {
@@ -728,11 +700,10 @@ describe("argumentValueValidation tests", () => {
728
700
  type: ArgumentValueTypeName.BOOLEAN,
729
701
  isVarargMultiple: true,
730
702
  };
731
- expect(
732
- validatePositionalValue(positional, ["true", "false"], invalidArguments),
733
- ).toEqual(
734
- [true, false],
735
- );
703
+ expect(validatePositionalValue(positional, ["true", "false"], invalidArguments)).toEqual([
704
+ true,
705
+ false,
706
+ ]);
736
707
  expect(invalidArguments).toEqual([]);
737
708
 
738
709
  positional = {
@@ -740,14 +711,14 @@ describe("argumentValueValidation tests", () => {
740
711
  type: ArgumentValueTypeName.BOOLEAN,
741
712
  isVarargMultiple: true,
742
713
  };
743
- expect(
744
- validatePositionalValue(positional, undefined, invalidArguments),
745
- ).toBeUndefined();
746
- expect(invalidArguments).toEqual([{
747
- argument: positional,
748
- name: "foo",
749
- reason: InvalidArgumentReason.MISSING_VALUE,
750
- }]);
714
+ expect(validatePositionalValue(positional, undefined, invalidArguments)).toBeUndefined();
715
+ expect(invalidArguments).toEqual([
716
+ {
717
+ argument: positional,
718
+ name: "foo",
719
+ reason: InvalidArgumentReason.MISSING_VALUE,
720
+ },
721
+ ]);
751
722
  });
752
723
 
753
724
  test("Positional varargs optional", () => {
@@ -757,9 +728,7 @@ describe("argumentValueValidation tests", () => {
757
728
  isVarargOptional: true,
758
729
  };
759
730
  let invalidArguments: Array<InvalidArgument> = [];
760
- expect(
761
- validatePositionalValue(positional, undefined, invalidArguments),
762
- ).toBeUndefined();
731
+ expect(validatePositionalValue(positional, undefined, invalidArguments)).toBeUndefined();
763
732
  expect(invalidArguments).toEqual([]);
764
733
 
765
734
  positional = {
@@ -767,10 +736,7 @@ describe("argumentValueValidation tests", () => {
767
736
  type: ArgumentValueTypeName.STRING,
768
737
  isVarargOptional: true,
769
738
  };
770
- expect(
771
- validatePositionalValue(positional, "foo", invalidArguments),
772
- "foo",
773
- );
739
+ expect(validatePositionalValue(positional, "foo", invalidArguments), "foo");
774
740
  expect(invalidArguments).toEqual([]);
775
741
 
776
742
  positional = {
@@ -778,15 +744,15 @@ describe("argumentValueValidation tests", () => {
778
744
  type: ArgumentValueTypeName.STRING,
779
745
  isVarargOptional: true,
780
746
  };
781
- expect(
782
- validatePositionalValue(positional, ["foo", "bar"], invalidArguments),
783
- ).toBeUndefined();
784
- expect(invalidArguments).toEqual([{
785
- argument: positional,
786
- name: "foo",
787
- value: ["foo", "bar"],
788
- reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
789
- }]);
747
+ expect(validatePositionalValue(positional, ["foo", "bar"], invalidArguments)).toBeUndefined();
748
+ expect(invalidArguments).toEqual([
749
+ {
750
+ argument: positional,
751
+ name: "foo",
752
+ value: ["foo", "bar"],
753
+ reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
754
+ },
755
+ ]);
790
756
 
791
757
  positional = {
792
758
  name: "foo",
@@ -795,11 +761,10 @@ describe("argumentValueValidation tests", () => {
795
761
  isVarargOptional: true,
796
762
  };
797
763
  invalidArguments = [];
798
- expect(
799
- validatePositionalValue(positional, ["foo", "bar"], invalidArguments),
800
- ).toEqual(
801
- ["foo", "bar"],
802
- );
764
+ expect(validatePositionalValue(positional, ["foo", "bar"], invalidArguments)).toEqual([
765
+ "foo",
766
+ "bar",
767
+ ]);
803
768
  expect(invalidArguments).toEqual([]);
804
769
  });
805
770
 
@@ -810,10 +775,7 @@ describe("argumentValueValidation tests", () => {
810
775
  allowableValues: ["bar", "two"],
811
776
  };
812
777
  const invalidArguments: Array<InvalidArgument> = [];
813
- expect(
814
- validatePositionalValue(positional, "bar", invalidArguments),
815
- "bar",
816
- );
778
+ expect(validatePositionalValue(positional, "bar", invalidArguments), "bar");
817
779
  expect(invalidArguments).toEqual([]);
818
780
 
819
781
  positional = {
@@ -821,135 +783,79 @@ describe("argumentValueValidation tests", () => {
821
783
  type: ArgumentValueTypeName.STRING,
822
784
  allowableValues: ["bar", "two"],
823
785
  };
824
- expect(
825
- validatePositionalValue(positional, "goo", invalidArguments),
826
- ).toBeUndefined();
827
- expect(invalidArguments).toEqual([{
828
- argument: positional,
829
- name: "foo",
830
- value: "goo",
831
- reason: InvalidArgumentReason.ILLEGAL_VALUE,
832
- }]);
786
+ expect(validatePositionalValue(positional, "goo", invalidArguments)).toBeUndefined();
787
+ expect(invalidArguments).toEqual([
788
+ {
789
+ argument: positional,
790
+ name: "foo",
791
+ value: "goo",
792
+ reason: InvalidArgumentReason.ILLEGAL_VALUE,
793
+ },
794
+ ]);
833
795
  });
834
796
 
835
797
  test("Global command argument types", () => {
836
798
  let globalCommandArgument: GlobalCommandArgument = {
837
799
  type: ArgumentValueTypeName.STRING,
838
800
  };
839
- let globalCommand = getGlobalCommandWithShortAlias(
840
- "globalCommand",
841
- "f",
842
- globalCommandArgument,
843
- );
801
+ let globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
844
802
  let invalidArguments: Array<InvalidArgument> = [];
845
- expect(
846
- validateGlobalCommandArgumentValue(
847
- globalCommand,
848
- "foo",
849
- invalidArguments,
850
- ),
851
- "foo",
852
- );
803
+ expect(validateGlobalCommandArgumentValue(globalCommand, "foo", invalidArguments), "foo");
853
804
  expect(invalidArguments).toEqual([]);
854
805
 
855
806
  globalCommandArgument = {
856
807
  type: ArgumentValueTypeName.NUMBER,
857
808
  };
858
- globalCommand = getGlobalCommandWithShortAlias(
859
- "globalCommand",
860
- "f",
861
- globalCommandArgument,
862
- );
863
- expect(
864
- validateGlobalCommandArgumentValue(
865
- globalCommand,
866
- "1",
867
- invalidArguments,
868
- ),
869
- ).toEqual(
870
- 1,
871
- );
809
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
810
+ expect(validateGlobalCommandArgumentValue(globalCommand, "1", invalidArguments)).toEqual(1);
872
811
  expect(invalidArguments).toEqual([]);
873
812
 
874
813
  globalCommandArgument = {
875
814
  type: ArgumentValueTypeName.BOOLEAN,
876
815
  };
877
- globalCommand = getGlobalCommandWithShortAlias(
878
- "globalCommand",
879
- "f",
880
- globalCommandArgument,
881
- );
882
- expect(
883
- validateGlobalCommandArgumentValue(
884
- globalCommand,
885
- "true",
886
- invalidArguments,
887
- ),
888
- ).toBeTrue();
816
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
817
+ expect(validateGlobalCommandArgumentValue(globalCommand, "true", invalidArguments)).toBeTrue();
889
818
  expect(invalidArguments).toEqual([]);
890
819
 
891
820
  globalCommandArgument = {
892
821
  type: ArgumentValueTypeName.STRING,
893
822
  };
894
- globalCommand = getGlobalCommandWithShortAlias(
895
- "globalCommand",
896
- "f",
897
- globalCommandArgument,
898
- );
899
- expect(
900
- validateGlobalCommandArgumentValue(
901
- globalCommand,
902
- "1",
903
- invalidArguments,
904
- ),
905
- "1",
906
- );
823
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
824
+ expect(validateGlobalCommandArgumentValue(globalCommand, "1", invalidArguments), "1");
907
825
  expect(invalidArguments).toEqual([]);
908
826
 
909
827
  globalCommandArgument = {
910
828
  type: ArgumentValueTypeName.NUMBER,
911
829
  };
912
- globalCommand = getGlobalCommandWithShortAlias(
913
- "globalCommand",
914
- "f",
915
- globalCommandArgument,
916
- );
830
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
917
831
  expect(
918
- validateGlobalCommandArgumentValue(
919
- globalCommand,
920
- "foo",
921
- invalidArguments,
922
- ),
832
+ validateGlobalCommandArgumentValue(globalCommand, "foo", invalidArguments),
923
833
  ).toBeUndefined();
924
- expect(invalidArguments).toEqual([{
925
- argument: globalCommandArgument,
926
- name: "globalCommand",
927
- value: "foo",
928
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
929
- }]);
834
+ expect(invalidArguments).toEqual([
835
+ {
836
+ argument: globalCommandArgument,
837
+ name: "globalCommand",
838
+ value: "foo",
839
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
840
+ },
841
+ ]);
930
842
 
931
843
  globalCommandArgument = {
932
844
  type: ArgumentValueTypeName.BOOLEAN,
933
845
  };
934
- globalCommand = getGlobalCommandWithShortAlias(
935
- "globalCommand",
936
- "f",
937
- globalCommandArgument,
938
- );
846
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
939
847
  invalidArguments = [];
940
848
  expect(
941
- validateGlobalCommandArgumentValue(
942
- globalCommand,
943
- "foo",
944
- invalidArguments,
945
- ),
849
+ validateGlobalCommandArgumentValue(globalCommand, "foo", invalidArguments),
946
850
  ).toBeUndefined();
947
- expect(invalidArguments).toEqual([{
948
- argument: globalCommandArgument,
949
- name: "globalCommand",
950
- value: "foo",
951
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
952
- }]);
851
+ expect(invalidArguments).toEqual([
852
+ {
853
+ argument: globalCommandArgument,
854
+ name: "globalCommand",
855
+ value: "foo",
856
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
857
+ },
858
+ ]);
953
859
  });
954
860
 
955
861
  test("Optional global command argument", () => {
@@ -957,41 +863,27 @@ describe("argumentValueValidation tests", () => {
957
863
  type: ArgumentValueTypeName.STRING,
958
864
  isOptional: true,
959
865
  };
960
- let globalCommand = getGlobalCommandWithShortAlias(
961
- "globalCommand",
962
- "f",
963
- globalCommandArgument,
964
- );
866
+ let globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
965
867
  const invalidArguments: Array<InvalidArgument> = [];
966
868
  expect(
967
- validateGlobalCommandArgumentValue(
968
- globalCommand,
969
- undefined,
970
- invalidArguments,
971
- ),
869
+ validateGlobalCommandArgumentValue(globalCommand, undefined, invalidArguments),
972
870
  ).toBeUndefined();
973
871
  expect(invalidArguments).toEqual([]);
974
872
 
975
873
  globalCommandArgument = {
976
874
  type: ArgumentValueTypeName.STRING,
977
875
  };
978
- globalCommand = getGlobalCommandWithShortAlias(
979
- "globalCommand",
980
- "f",
981
- globalCommandArgument,
982
- );
876
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
983
877
  expect(
984
- validateGlobalCommandArgumentValue(
985
- globalCommand,
986
- undefined,
987
- invalidArguments,
988
- ),
878
+ validateGlobalCommandArgumentValue(globalCommand, undefined, invalidArguments),
989
879
  ).toBeUndefined();
990
- expect(invalidArguments).toEqual([{
991
- argument: globalCommandArgument,
992
- name: "globalCommand",
993
- reason: InvalidArgumentReason.MISSING_VALUE,
994
- }]);
880
+ expect(invalidArguments).toEqual([
881
+ {
882
+ argument: globalCommandArgument,
883
+ name: "globalCommand",
884
+ reason: InvalidArgumentReason.MISSING_VALUE,
885
+ },
886
+ ]);
995
887
  });
996
888
 
997
889
  test("Option with custom validator that passes", () => {
@@ -1001,9 +893,7 @@ describe("argumentValueValidation tests", () => {
1001
893
  validate: () => undefined,
1002
894
  };
1003
895
  const invalidArguments: Array<InvalidArgument> = [];
1004
- expect(validateOptionValue(option, "hello", invalidArguments)).toEqual(
1005
- "hello",
1006
- );
896
+ expect(validateOptionValue(option, "hello", invalidArguments)).toEqual("hello");
1007
897
  expect(invalidArguments).toEqual([]);
1008
898
  });
1009
899
 
@@ -1011,51 +901,48 @@ describe("argumentValueValidation tests", () => {
1011
901
  const option: Option = {
1012
902
  name: "foo",
1013
903
  type: ArgumentValueTypeName.STRING,
1014
- validate: (v) => (v as string).length < 3 ? "min 3 chars" : undefined,
904
+ validate: (v) => ((v as string).length < 3 ? "min 3 chars" : undefined),
1015
905
  };
1016
906
  const invalidArguments: Array<InvalidArgument> = [];
1017
- expect(
1018
- validateOptionValue(option, "ab", invalidArguments),
1019
- ).toBeUndefined();
1020
- expect(invalidArguments).toEqual([{
1021
- argument: option,
1022
- name: "foo",
1023
- value: "ab",
1024
- reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1025
- message: "min 3 chars",
1026
- }]);
907
+ expect(validateOptionValue(option, "ab", invalidArguments)).toBeUndefined();
908
+ expect(invalidArguments).toEqual([
909
+ {
910
+ argument: option,
911
+ name: "foo",
912
+ value: "ab",
913
+ reason: InvalidArgumentReason.CUSTOM_VALIDATION,
914
+ message: "min 3 chars",
915
+ },
916
+ ]);
1027
917
  });
1028
918
 
1029
919
  test("Positional with custom validator that passes and fails", () => {
1030
920
  const positional: Positional = {
1031
921
  name: "count",
1032
922
  type: ArgumentValueTypeName.NUMBER,
1033
- validate: (v) => (v as number) % 2 !== 0 ? "must be even" : undefined,
923
+ validate: (v) => ((v as number) % 2 !== 0 ? "must be even" : undefined),
1034
924
  };
1035
925
  let invalidArguments: Array<InvalidArgument> = [];
1036
- expect(
1037
- validatePositionalValue(positional, "4", invalidArguments),
1038
- ).toEqual(4);
926
+ expect(validatePositionalValue(positional, "4", invalidArguments)).toEqual(4);
1039
927
  expect(invalidArguments).toEqual([]);
1040
928
 
1041
929
  invalidArguments = [];
1042
- expect(
1043
- validatePositionalValue(positional, "3", invalidArguments),
1044
- ).toBeUndefined();
1045
- expect(invalidArguments).toEqual([{
1046
- argument: positional,
1047
- name: "count",
1048
- value: 3,
1049
- reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1050
- message: "must be even",
1051
- }]);
930
+ expect(validatePositionalValue(positional, "3", invalidArguments)).toBeUndefined();
931
+ expect(invalidArguments).toEqual([
932
+ {
933
+ argument: positional,
934
+ name: "count",
935
+ value: 3,
936
+ reason: InvalidArgumentReason.CUSTOM_VALIDATION,
937
+ message: "must be even",
938
+ },
939
+ ]);
1052
940
  });
1053
941
 
1054
942
  test("GlobalCommand argument with custom validator that passes and fails", () => {
1055
943
  const globalCommandArgument: GlobalCommandArgument = {
1056
944
  type: ArgumentValueTypeName.STRING,
1057
- validate: (v) =>
1058
- (v as string).startsWith("x") ? undefined : "must start with x",
945
+ validate: (v) => ((v as string).startsWith("x") ? undefined : "must start with x"),
1059
946
  };
1060
947
  const globalCommand = getGlobalCommandWithShortAlias(
1061
948
  "globalCommand",
@@ -1063,30 +950,24 @@ describe("argumentValueValidation tests", () => {
1063
950
  globalCommandArgument,
1064
951
  );
1065
952
  let invalidArguments: Array<InvalidArgument> = [];
1066
- expect(
1067
- validateGlobalCommandArgumentValue(
1068
- globalCommand,
1069
- "xfoo",
1070
- invalidArguments,
1071
- ),
1072
- ).toEqual("xfoo");
953
+ expect(validateGlobalCommandArgumentValue(globalCommand, "xfoo", invalidArguments)).toEqual(
954
+ "xfoo",
955
+ );
1073
956
  expect(invalidArguments).toEqual([]);
1074
957
 
1075
958
  invalidArguments = [];
1076
959
  expect(
1077
- validateGlobalCommandArgumentValue(
1078
- globalCommand,
1079
- "bar",
1080
- invalidArguments,
1081
- ),
960
+ validateGlobalCommandArgumentValue(globalCommand, "bar", invalidArguments),
1082
961
  ).toBeUndefined();
1083
- expect(invalidArguments).toEqual([{
1084
- argument: globalCommandArgument,
1085
- name: "globalCommand",
1086
- value: "bar",
1087
- reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1088
- message: "must start with x",
1089
- }]);
962
+ expect(invalidArguments).toEqual([
963
+ {
964
+ argument: globalCommandArgument,
965
+ name: "globalCommand",
966
+ value: "bar",
967
+ reason: InvalidArgumentReason.CUSTOM_VALIDATION,
968
+ message: "must start with x",
969
+ },
970
+ ]);
1090
971
  });
1091
972
 
1092
973
  test("Option isArray with custom validator checking uniqueness", () => {
@@ -1096,28 +977,24 @@ describe("argumentValueValidation tests", () => {
1096
977
  isArray: true,
1097
978
  validate: (v) => {
1098
979
  const arr = v as string[];
1099
- return new Set(arr).size !== arr.length
1100
- ? "values must be unique"
1101
- : undefined;
980
+ return new Set(arr).size !== arr.length ? "values must be unique" : undefined;
1102
981
  },
1103
982
  };
1104
983
  let invalidArguments: Array<InvalidArgument> = [];
1105
- expect(
1106
- validateOptionValue(option, ["a", "b", "c"], invalidArguments),
1107
- ).toEqual(["a", "b", "c"]);
984
+ expect(validateOptionValue(option, ["a", "b", "c"], invalidArguments)).toEqual(["a", "b", "c"]);
1108
985
  expect(invalidArguments).toEqual([]);
1109
986
 
1110
987
  invalidArguments = [];
1111
- expect(
1112
- validateOptionValue(option, ["a", "b", "a"], invalidArguments),
1113
- ).toBeUndefined();
1114
- expect(invalidArguments).toEqual([{
1115
- argument: option,
1116
- name: "tags",
1117
- value: ["a", "b", "a"],
1118
- reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1119
- message: "values must be unique",
1120
- }]);
988
+ expect(validateOptionValue(option, ["a", "b", "a"], invalidArguments)).toBeUndefined();
989
+ expect(invalidArguments).toEqual([
990
+ {
991
+ argument: option,
992
+ name: "tags",
993
+ value: ["a", "b", "a"],
994
+ reason: InvalidArgumentReason.CUSTOM_VALIDATION,
995
+ message: "values must be unique",
996
+ },
997
+ ]);
1121
998
  });
1122
999
 
1123
1000
  test("Positional isVarargMultiple with custom validator checking uniqueness", () => {
@@ -1127,28 +1004,26 @@ describe("argumentValueValidation tests", () => {
1127
1004
  isVarargMultiple: true,
1128
1005
  validate: (v) => {
1129
1006
  const arr = v as number[];
1130
- return new Set(arr).size !== arr.length
1131
- ? "values must be unique"
1132
- : undefined;
1007
+ return new Set(arr).size !== arr.length ? "values must be unique" : undefined;
1133
1008
  },
1134
1009
  };
1135
1010
  let invalidArguments: Array<InvalidArgument> = [];
1136
- expect(
1137
- validatePositionalValue(positional, ["1", "2", "3"], invalidArguments),
1138
- ).toEqual([1, 2, 3]);
1011
+ expect(validatePositionalValue(positional, ["1", "2", "3"], invalidArguments)).toEqual([
1012
+ 1, 2, 3,
1013
+ ]);
1139
1014
  expect(invalidArguments).toEqual([]);
1140
1015
 
1141
1016
  invalidArguments = [];
1142
- expect(
1143
- validatePositionalValue(positional, ["1", "2", "1"], invalidArguments),
1144
- ).toBeUndefined();
1145
- expect(invalidArguments).toEqual([{
1146
- argument: positional,
1147
- name: "ids",
1148
- value: [1, 2, 1],
1149
- reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1150
- message: "values must be unique",
1151
- }]);
1017
+ expect(validatePositionalValue(positional, ["1", "2", "1"], invalidArguments)).toBeUndefined();
1018
+ expect(invalidArguments).toEqual([
1019
+ {
1020
+ argument: positional,
1021
+ name: "ids",
1022
+ value: [1, 2, 1],
1023
+ reason: InvalidArgumentReason.CUSTOM_VALIDATION,
1024
+ message: "values must be unique",
1025
+ },
1026
+ ]);
1152
1027
  });
1153
1028
 
1154
1029
  test("Custom validator not called when built-in validation fails", () => {
@@ -1160,15 +1035,15 @@ describe("argumentValueValidation tests", () => {
1160
1035
  },
1161
1036
  };
1162
1037
  const invalidArguments: Array<InvalidArgument> = [];
1163
- expect(
1164
- validateOptionValue(option, "notanumber", invalidArguments),
1165
- ).toBeUndefined();
1166
- expect(invalidArguments).toEqual([{
1167
- argument: option,
1168
- name: "foo",
1169
- value: "notanumber",
1170
- reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
1171
- }]);
1038
+ expect(validateOptionValue(option, "notanumber", invalidArguments)).toBeUndefined();
1039
+ expect(invalidArguments).toEqual([
1040
+ {
1041
+ argument: option,
1042
+ name: "foo",
1043
+ value: "notanumber",
1044
+ reason: InvalidArgumentReason.INCORRECT_VALUE_TYPE,
1045
+ },
1046
+ ]);
1172
1047
  });
1173
1048
 
1174
1049
  test("Custom validator not called when value is undefined and optional", () => {
@@ -1181,9 +1056,7 @@ describe("argumentValueValidation tests", () => {
1181
1056
  },
1182
1057
  };
1183
1058
  const invalidArguments: Array<InvalidArgument> = [];
1184
- expect(
1185
- validateOptionValue(option, undefined, invalidArguments),
1186
- ).toBeUndefined();
1059
+ expect(validateOptionValue(option, undefined, invalidArguments)).toBeUndefined();
1187
1060
  expect(invalidArguments).toEqual([]);
1188
1061
  });
1189
1062
 
@@ -1192,43 +1065,26 @@ describe("argumentValueValidation tests", () => {
1192
1065
  type: ArgumentValueTypeName.STRING,
1193
1066
  allowableValues: ["bar", "two"],
1194
1067
  };
1195
- let globalCommand = getGlobalCommandWithShortAlias(
1196
- "globalCommand",
1197
- "f",
1198
- globalCommandArgument,
1199
- );
1068
+ let globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
1200
1069
  const invalidArguments: Array<InvalidArgument> = [];
1201
- expect(
1202
- validateGlobalCommandArgumentValue(
1203
- globalCommand,
1204
- "bar",
1205
- invalidArguments,
1206
- ),
1207
- "bar",
1208
- );
1070
+ expect(validateGlobalCommandArgumentValue(globalCommand, "bar", invalidArguments), "bar");
1209
1071
  expect(invalidArguments).toEqual([]);
1210
1072
 
1211
1073
  globalCommandArgument = {
1212
1074
  type: ArgumentValueTypeName.STRING,
1213
1075
  allowableValues: ["bar", "two"],
1214
1076
  };
1215
- globalCommand = getGlobalCommandWithShortAlias(
1216
- "globalCommand",
1217
- "f",
1218
- globalCommandArgument,
1219
- );
1077
+ globalCommand = getGlobalCommandWithShortAlias("globalCommand", "f", globalCommandArgument);
1220
1078
  expect(
1221
- validateGlobalCommandArgumentValue(
1222
- globalCommand,
1223
- "goo",
1224
- invalidArguments,
1225
- ),
1079
+ validateGlobalCommandArgumentValue(globalCommand, "goo", invalidArguments),
1226
1080
  ).toBeUndefined();
1227
- expect(invalidArguments).toEqual([{
1228
- argument: globalCommandArgument,
1229
- name: "globalCommand",
1230
- value: "goo",
1231
- reason: InvalidArgumentReason.ILLEGAL_VALUE,
1232
- }]);
1081
+ expect(invalidArguments).toEqual([
1082
+ {
1083
+ argument: globalCommandArgument,
1084
+ name: "globalCommand",
1085
+ value: "goo",
1086
+ reason: InvalidArgumentReason.ILLEGAL_VALUE,
1087
+ },
1088
+ ]);
1233
1089
  });
1234
1090
  });