@flowscripter/dynamic-cli-framework 7.0.4 → 7.0.6
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/src/cli/BaseCLI.d.ts +3 -0
- package/dist/src/cli/BaseCLI.d.ts.map +1 -1
- package/dist/src/cli/BaseCLI.js +6 -1
- package/dist/src/runtime/values/argumentValueValidation.d.ts.map +1 -1
- package/dist/src/runtime/values/argumentValueValidation.js +66 -86
- package/package.json +1 -1
- package/src/cli/BaseCLI.ts +6 -1
- package/src/runtime/values/argumentValueValidation.ts +84 -98
|
@@ -31,6 +31,9 @@ import type BaseCLIFeatureOptions from "./BaseCLIFeatureOptions.ts";
|
|
|
31
31
|
* * {@link UpgradeServiceProvider}
|
|
32
32
|
* * {@link PluginServiceProvider}
|
|
33
33
|
*
|
|
34
|
+
* Enabling the plugin service also registers {@link SpawnServiceProvider}, as plugin installation
|
|
35
|
+
* spawns the package manager via the spawn service.
|
|
36
|
+
*
|
|
34
37
|
* `keyReader` is optional. If omitted, or if the stderr {@link Terminal} is not a TTY, prompting is
|
|
35
38
|
* unavailable: {@link PrompterServiceProvider} (and {@link ArgumentPrompterServiceProvider}, if
|
|
36
39
|
* enabled) are simply not registered. If `promptingEnabled` is `true` in that situation, {@link run}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCLI.d.ts","sourceRoot":"","sources":["../../../src/cli/BaseCLI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yCAAyC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAGvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAsBzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAS3E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAGpD,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AAkBpE
|
|
1
|
+
{"version":3,"file":"BaseCLI.d.ts","sourceRoot":"","sources":["../../../src/cli/BaseCLI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yCAAyC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAGvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAsBzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAS3E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAGpD,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AAkBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,YAAW,GAAG;;IAazC,YACE,SAAS,EAAE,SAAS,EACpB,oBAAoB,EAAE,cAAc,EACpC,oBAAoB,EAAE,cAAc,EACpC,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,OAAO,EACtB,cAAc,EAAE,QAAQ,EACxB,cAAc,EAAE,QAAQ,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,qBAAqB,EAoEhC;IAED;;;;;;;OAOG;IACI,kBAAkB,CAAC,eAAe,EAAE,eAAe,QAEzD;IAED;;;;;;;;OAQG;IACH;;;;;OAKG;IACI,cAAc,CAAC,IAAI,EAAE,WAAW,QAEtC;IAEM,UAAU,CAAC,OAAO,EAAE,OAAO,QAQjC;IAEK,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAwOzD;CACF"}
|
package/dist/src/cli/BaseCLI.js
CHANGED
|
@@ -54,6 +54,9 @@ const logger = getLogger("BaseCLI");
|
|
|
54
54
|
* * {@link UpgradeServiceProvider}
|
|
55
55
|
* * {@link PluginServiceProvider}
|
|
56
56
|
*
|
|
57
|
+
* Enabling the plugin service also registers {@link SpawnServiceProvider}, as plugin installation
|
|
58
|
+
* spawns the package manager via the spawn service.
|
|
59
|
+
*
|
|
57
60
|
* `keyReader` is optional. If omitted, or if the stderr {@link Terminal} is not a TTY, prompting is
|
|
58
61
|
* unavailable: {@link PrompterServiceProvider} (and {@link ArgumentPrompterServiceProvider}, if
|
|
59
62
|
* enabled) are simply not registered. If `promptingEnabled` is `true` in that situation, {@link run}
|
|
@@ -213,7 +216,9 @@ export default class BaseCLI {
|
|
|
213
216
|
logger.debug("Skipping ImagePrinterServiceProvider: imagePrinterServiceEnabled is true but stdout is not a TTY");
|
|
214
217
|
}
|
|
215
218
|
}
|
|
216
|
-
|
|
219
|
+
// The plugin service routes package manager output through SpawnService so that it is
|
|
220
|
+
// quoted, marked and cleared on success; enabling plugins therefore also enables spawning.
|
|
221
|
+
if (this.#options.spawnServiceEnabled || this.#options.pluginServiceEnabled) {
|
|
217
222
|
this.addServiceProvider(new SpawnServiceProvider(58));
|
|
218
223
|
}
|
|
219
224
|
if (this.#options.fetchServiceEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argumentValueValidation.d.ts","sourceRoot":"","sources":["../../../../src/runtime/values/argumentValueValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAI/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"argumentValueValidation.d.ts","sourceRoot":"","sources":["../../../../src/runtime/values/argumentValueValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAI/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAgb7E;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,KAAK,EAAE,kBAAkB,GAAG,eAAe,GAAG,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC,EAChF,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,GACvC,kBAAkB,GAAG,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,CAQ/D;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,kBAAkB,EACzB,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,GACvC,kBAAkB,CAQpB;AAED;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,wBAAwB,EAC/B,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,GACvC,wBAAwB,CA+C1B;AAED,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,OAAO,GACnB,MAAM,CA+DR"}
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { ValueTypeName, ComplexValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
2
|
import { isComplexOption } from "../argument/ArgumentTypeGuards.js";
|
|
3
3
|
import { InvalidArgumentReason } from "@flowscripter/dynamic-cli-framework-api";
|
|
4
|
+
/**
|
|
5
|
+
* Returns a copy of the provided {@link InvalidArgument} with the provided prefix prepended to its name.
|
|
6
|
+
*/
|
|
7
|
+
function withPrefix(invalidArgument, prefix) {
|
|
8
|
+
return { ...invalidArgument, name: `${prefix}${invalidArgument.name ?? ""}` };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Invokes the custom validate function (if any) of the provided {@link Argument} and returns an
|
|
12
|
+
* {@link InvalidArgument} if the custom validation failed.
|
|
13
|
+
*
|
|
14
|
+
* @param argument the {@link Argument} providing the custom validate function.
|
|
15
|
+
* @param name the name to use for the {@link InvalidArgument}.
|
|
16
|
+
* @param value the validated and type-converted value.
|
|
17
|
+
*/
|
|
18
|
+
function doCustomValidation(argument, name, value) {
|
|
19
|
+
if (argument.validate === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const message = argument.validate(value);
|
|
23
|
+
if (message === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
argument,
|
|
28
|
+
name,
|
|
29
|
+
value: value,
|
|
30
|
+
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
31
|
+
message,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
4
34
|
/**
|
|
5
35
|
* Validates the provided primitive value against the provided {@link Argument}.
|
|
6
36
|
*
|
|
@@ -162,27 +192,10 @@ function validateArrayValue(subCommandArgument, arrayValue) {
|
|
|
162
192
|
}
|
|
163
193
|
if (validationResult.invalidArgument) {
|
|
164
194
|
// fast fail
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
argument: validationResult.invalidArgument.argument,
|
|
170
|
-
name: `[${i}]${validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""}`,
|
|
171
|
-
value: validationResult.invalidArgument.value,
|
|
172
|
-
reason: validationResult.invalidArgument.reason,
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
return {
|
|
178
|
-
validValue: convertedArrayValue,
|
|
179
|
-
invalidArgument: {
|
|
180
|
-
argument: validationResult.invalidArgument.argument,
|
|
181
|
-
name: `[${i}]${validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""}`,
|
|
182
|
-
reason: validationResult.invalidArgument.reason,
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|
|
195
|
+
return {
|
|
196
|
+
validValue: convertedArrayValue,
|
|
197
|
+
invalidArgument: withPrefix(validationResult.invalidArgument, `[${i}]`),
|
|
198
|
+
};
|
|
186
199
|
}
|
|
187
200
|
}
|
|
188
201
|
return {
|
|
@@ -193,8 +206,14 @@ function validateObjectValue(argument, objectValue) {
|
|
|
193
206
|
const convertedObjectValue = {};
|
|
194
207
|
for (let i = 0; i < argument.properties.length; i++) {
|
|
195
208
|
const propertyArg = argument.properties[i];
|
|
196
|
-
|
|
209
|
+
let propertyValue = objectValue[propertyArg.name];
|
|
210
|
+
if (propertyValue === undefined && propertyArg.defaultValue !== undefined) {
|
|
211
|
+
propertyValue = propertyArg.defaultValue;
|
|
212
|
+
}
|
|
197
213
|
if (propertyValue === undefined) {
|
|
214
|
+
if (propertyArg.isOptional) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
198
217
|
return {
|
|
199
218
|
validValue: convertedObjectValue,
|
|
200
219
|
invalidArgument: {
|
|
@@ -252,27 +271,18 @@ function validateObjectValue(argument, objectValue) {
|
|
|
252
271
|
}
|
|
253
272
|
// fast fail
|
|
254
273
|
if (validationResult.invalidArgument !== undefined) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
validValue: convertedObjectValue,
|
|
269
|
-
invalidArgument: {
|
|
270
|
-
argument: validationResult.invalidArgument.argument,
|
|
271
|
-
name: `.${propertyArg.name}${validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""}`,
|
|
272
|
-
reason: validationResult.invalidArgument.reason,
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
}
|
|
274
|
+
return {
|
|
275
|
+
validValue: convertedObjectValue,
|
|
276
|
+
invalidArgument: withPrefix(validationResult.invalidArgument, `.${propertyArg.name}`),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
// custom validation runs only once the property (and any nested properties) passed validation
|
|
280
|
+
const customInvalidArgument = doCustomValidation(propertyArg, `.${propertyArg.name}`, validationResult.validValue);
|
|
281
|
+
if (customInvalidArgument !== undefined) {
|
|
282
|
+
return {
|
|
283
|
+
validValue: convertedObjectValue,
|
|
284
|
+
invalidArgument: customInvalidArgument,
|
|
285
|
+
};
|
|
276
286
|
}
|
|
277
287
|
}
|
|
278
288
|
return {
|
|
@@ -320,38 +330,13 @@ function doSubCommandArgumentValidation(argument, value, isArray, isOptional, in
|
|
|
320
330
|
validationResult = validatePrimitiveValue(argument, value);
|
|
321
331
|
}
|
|
322
332
|
if (validationResult.invalidArgument !== undefined) {
|
|
323
|
-
|
|
324
|
-
validationResult.invalidArgument = {
|
|
325
|
-
argument: validationResult.invalidArgument.argument,
|
|
326
|
-
name: `${argument.name}${validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""}`,
|
|
327
|
-
value: validationResult.invalidArgument.value,
|
|
328
|
-
reason: validationResult.invalidArgument.reason,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
validationResult.invalidArgument = {
|
|
333
|
-
argument: validationResult.invalidArgument.argument,
|
|
334
|
-
name: `${argument.name}${validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""}`,
|
|
335
|
-
reason: validationResult.invalidArgument.reason,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (validationResult.invalidArgument) {
|
|
340
|
-
invalidArguments.push(validationResult.invalidArgument);
|
|
333
|
+
invalidArguments.push(withPrefix(validationResult.invalidArgument, argument.name));
|
|
341
334
|
return undefined;
|
|
342
335
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
argument,
|
|
348
|
-
name: argument.name,
|
|
349
|
-
value: validationResult.validValue,
|
|
350
|
-
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
351
|
-
message: customError,
|
|
352
|
-
});
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
336
|
+
const customInvalidArgument = doCustomValidation(argument, argument.name, validationResult.validValue);
|
|
337
|
+
if (customInvalidArgument !== undefined) {
|
|
338
|
+
invalidArguments.push(customInvalidArgument);
|
|
339
|
+
return undefined;
|
|
355
340
|
}
|
|
356
341
|
return validationResult.validValue;
|
|
357
342
|
}
|
|
@@ -417,18 +402,10 @@ export function validateGlobalCommandArgumentValue(globalCommand, value, invalid
|
|
|
417
402
|
}
|
|
418
403
|
return undefined;
|
|
419
404
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
argument: globalCommandArgument,
|
|
425
|
-
name: globalCommand.name,
|
|
426
|
-
value: validationResult.validValue,
|
|
427
|
-
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
428
|
-
message: customError,
|
|
429
|
-
});
|
|
430
|
-
return undefined;
|
|
431
|
-
}
|
|
405
|
+
const customInvalidArgument = doCustomValidation(globalCommandArgument, globalCommand.name, validationResult.validValue);
|
|
406
|
+
if (customInvalidArgument !== undefined) {
|
|
407
|
+
invalidArguments.push(customInvalidArgument);
|
|
408
|
+
return undefined;
|
|
432
409
|
}
|
|
433
410
|
return validationResult.validValue;
|
|
434
411
|
}
|
|
@@ -449,7 +426,10 @@ export function getInvalidArgumentString(invalidArgument, skipArgName) {
|
|
|
449
426
|
}
|
|
450
427
|
let valueString = "";
|
|
451
428
|
if (invalidArgument.value !== undefined) {
|
|
452
|
-
valueString =
|
|
429
|
+
valueString =
|
|
430
|
+
typeof invalidArgument.value === "object"
|
|
431
|
+
? `'${JSON.stringify(invalidArgument.value)}'`
|
|
432
|
+
: `'${invalidArgument.value}'`;
|
|
453
433
|
}
|
|
454
434
|
let argString = "";
|
|
455
435
|
if (nameString !== "") {
|
package/package.json
CHANGED
package/src/cli/BaseCLI.ts
CHANGED
|
@@ -84,6 +84,9 @@ const logger = getLogger("BaseCLI");
|
|
|
84
84
|
* * {@link UpgradeServiceProvider}
|
|
85
85
|
* * {@link PluginServiceProvider}
|
|
86
86
|
*
|
|
87
|
+
* Enabling the plugin service also registers {@link SpawnServiceProvider}, as plugin installation
|
|
88
|
+
* spawns the package manager via the spawn service.
|
|
89
|
+
*
|
|
87
90
|
* `keyReader` is optional. If omitted, or if the stderr {@link Terminal} is not a TTY, prompting is
|
|
88
91
|
* unavailable: {@link PrompterServiceProvider} (and {@link ArgumentPrompterServiceProvider}, if
|
|
89
92
|
* enabled) are simply not registered. If `promptingEnabled` is `true` in that situation, {@link run}
|
|
@@ -299,7 +302,9 @@ export default class BaseCLI implements CLI {
|
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
304
|
|
|
302
|
-
|
|
305
|
+
// The plugin service routes package manager output through SpawnService so that it is
|
|
306
|
+
// quoted, marked and cleared on success; enabling plugins therefore also enables spawning.
|
|
307
|
+
if (this.#options.spawnServiceEnabled || this.#options.pluginServiceEnabled) {
|
|
303
308
|
this.addServiceProvider(new SpawnServiceProvider(58));
|
|
304
309
|
}
|
|
305
310
|
|
|
@@ -33,6 +33,42 @@ interface ObjectValueValidationResult extends ValidationResult {
|
|
|
33
33
|
validValue?: Values;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Returns a copy of the provided {@link InvalidArgument} with the provided prefix prepended to its name.
|
|
38
|
+
*/
|
|
39
|
+
function withPrefix(invalidArgument: InvalidArgument, prefix: string): InvalidArgument {
|
|
40
|
+
return { ...invalidArgument, name: `${prefix}${invalidArgument.name ?? ""}` };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Invokes the custom validate function (if any) of the provided {@link Argument} and returns an
|
|
45
|
+
* {@link InvalidArgument} if the custom validation failed.
|
|
46
|
+
*
|
|
47
|
+
* @param argument the {@link Argument} providing the custom validate function.
|
|
48
|
+
* @param name the name to use for the {@link InvalidArgument}.
|
|
49
|
+
* @param value the validated and type-converted value.
|
|
50
|
+
*/
|
|
51
|
+
function doCustomValidation(
|
|
52
|
+
argument: Argument | ComplexOption,
|
|
53
|
+
name: string,
|
|
54
|
+
value: SingleValueType | Values | Array<SingleValueType | Values>,
|
|
55
|
+
): InvalidArgument | undefined {
|
|
56
|
+
if (argument.validate === undefined) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const message = argument.validate(value as ValueType | Values | Array<Values>);
|
|
60
|
+
if (message === undefined) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
argument,
|
|
65
|
+
name,
|
|
66
|
+
value: value as PopulatedValueType | PopulatedValues,
|
|
67
|
+
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
68
|
+
message,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
36
72
|
/**
|
|
37
73
|
* Validates the provided primitive value against the provided {@link Argument}.
|
|
38
74
|
*
|
|
@@ -217,30 +253,10 @@ function validateArrayValue(
|
|
|
217
253
|
}
|
|
218
254
|
if (validationResult.invalidArgument) {
|
|
219
255
|
// fast fail
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
argument: validationResult.invalidArgument.argument,
|
|
225
|
-
name: `[${i}]${
|
|
226
|
-
validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""
|
|
227
|
-
}`,
|
|
228
|
-
value: validationResult.invalidArgument.value,
|
|
229
|
-
reason: validationResult.invalidArgument.reason,
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
} else {
|
|
233
|
-
return {
|
|
234
|
-
validValue: convertedArrayValue,
|
|
235
|
-
invalidArgument: {
|
|
236
|
-
argument: validationResult.invalidArgument.argument,
|
|
237
|
-
name: `[${i}]${
|
|
238
|
-
validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""
|
|
239
|
-
}`,
|
|
240
|
-
reason: validationResult.invalidArgument.reason,
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
}
|
|
256
|
+
return {
|
|
257
|
+
validValue: convertedArrayValue,
|
|
258
|
+
invalidArgument: withPrefix(validationResult.invalidArgument, `[${i}]`),
|
|
259
|
+
};
|
|
244
260
|
}
|
|
245
261
|
}
|
|
246
262
|
return {
|
|
@@ -256,9 +272,15 @@ function validateObjectValue(
|
|
|
256
272
|
|
|
257
273
|
for (let i = 0; i < argument.properties.length; i++) {
|
|
258
274
|
const propertyArg = argument.properties[i]!;
|
|
259
|
-
|
|
275
|
+
let propertyValue = objectValue[propertyArg.name];
|
|
260
276
|
|
|
277
|
+
if (propertyValue === undefined && propertyArg.defaultValue !== undefined) {
|
|
278
|
+
propertyValue = propertyArg.defaultValue as PopulatedValueType | PopulatedValues;
|
|
279
|
+
}
|
|
261
280
|
if (propertyValue === undefined) {
|
|
281
|
+
if (propertyArg.isOptional) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
262
284
|
return {
|
|
263
285
|
validValue: convertedObjectValue,
|
|
264
286
|
invalidArgument: {
|
|
@@ -329,30 +351,22 @@ function validateObjectValue(
|
|
|
329
351
|
}
|
|
330
352
|
// fast fail
|
|
331
353
|
if (validationResult.invalidArgument !== undefined) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
argument: validationResult.invalidArgument.argument,
|
|
349
|
-
name: `.${propertyArg.name}${
|
|
350
|
-
validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""
|
|
351
|
-
}`,
|
|
352
|
-
reason: validationResult.invalidArgument.reason,
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
}
|
|
354
|
+
return {
|
|
355
|
+
validValue: convertedObjectValue,
|
|
356
|
+
invalidArgument: withPrefix(validationResult.invalidArgument, `.${propertyArg.name}`),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
// custom validation runs only once the property (and any nested properties) passed validation
|
|
360
|
+
const customInvalidArgument = doCustomValidation(
|
|
361
|
+
propertyArg,
|
|
362
|
+
`.${propertyArg.name}`,
|
|
363
|
+
validationResult.validValue!,
|
|
364
|
+
);
|
|
365
|
+
if (customInvalidArgument !== undefined) {
|
|
366
|
+
return {
|
|
367
|
+
validValue: convertedObjectValue,
|
|
368
|
+
invalidArgument: customInvalidArgument,
|
|
369
|
+
};
|
|
356
370
|
}
|
|
357
371
|
}
|
|
358
372
|
return {
|
|
@@ -407,44 +421,17 @@ function doSubCommandArgumentValidation(
|
|
|
407
421
|
}
|
|
408
422
|
|
|
409
423
|
if (validationResult.invalidArgument !== undefined) {
|
|
410
|
-
|
|
411
|
-
validationResult.invalidArgument = {
|
|
412
|
-
argument: validationResult.invalidArgument.argument,
|
|
413
|
-
name: `${argument.name}${
|
|
414
|
-
validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""
|
|
415
|
-
}`,
|
|
416
|
-
value: validationResult.invalidArgument.value,
|
|
417
|
-
reason: validationResult.invalidArgument.reason,
|
|
418
|
-
};
|
|
419
|
-
} else {
|
|
420
|
-
validationResult.invalidArgument = {
|
|
421
|
-
argument: validationResult.invalidArgument.argument,
|
|
422
|
-
name: `${argument.name}${
|
|
423
|
-
validationResult.invalidArgument.name ? validationResult.invalidArgument.name : ""
|
|
424
|
-
}`,
|
|
425
|
-
reason: validationResult.invalidArgument.reason,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (validationResult.invalidArgument) {
|
|
431
|
-
invalidArguments.push(validationResult.invalidArgument);
|
|
424
|
+
invalidArguments.push(withPrefix(validationResult.invalidArgument, argument.name));
|
|
432
425
|
return undefined;
|
|
433
426
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
value: validationResult.validValue as PopulatedValueType,
|
|
443
|
-
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
444
|
-
message: customError,
|
|
445
|
-
});
|
|
446
|
-
return undefined;
|
|
447
|
-
}
|
|
427
|
+
const customInvalidArgument = doCustomValidation(
|
|
428
|
+
argument,
|
|
429
|
+
argument.name,
|
|
430
|
+
validationResult.validValue!,
|
|
431
|
+
);
|
|
432
|
+
if (customInvalidArgument !== undefined) {
|
|
433
|
+
invalidArguments.push(customInvalidArgument);
|
|
434
|
+
return undefined;
|
|
448
435
|
}
|
|
449
436
|
return validationResult.validValue as PopulatedValueType | PopulatedValues | undefined;
|
|
450
437
|
}
|
|
@@ -540,18 +527,14 @@ export function validateGlobalCommandArgumentValue(
|
|
|
540
527
|
return undefined;
|
|
541
528
|
}
|
|
542
529
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
message: customError,
|
|
552
|
-
});
|
|
553
|
-
return undefined;
|
|
554
|
-
}
|
|
530
|
+
const customInvalidArgument = doCustomValidation(
|
|
531
|
+
globalCommandArgument,
|
|
532
|
+
globalCommand.name,
|
|
533
|
+
validationResult.validValue!,
|
|
534
|
+
);
|
|
535
|
+
if (customInvalidArgument !== undefined) {
|
|
536
|
+
invalidArguments.push(customInvalidArgument);
|
|
537
|
+
return undefined;
|
|
555
538
|
}
|
|
556
539
|
return validationResult.validValue as PopulatedSingleValueType;
|
|
557
540
|
}
|
|
@@ -577,7 +560,10 @@ export function getInvalidArgumentString(
|
|
|
577
560
|
}
|
|
578
561
|
let valueString = "";
|
|
579
562
|
if (invalidArgument.value !== undefined) {
|
|
580
|
-
valueString =
|
|
563
|
+
valueString =
|
|
564
|
+
typeof invalidArgument.value === "object"
|
|
565
|
+
? `'${JSON.stringify(invalidArgument.value)}'`
|
|
566
|
+
: `'${invalidArgument.value}'`;
|
|
581
567
|
}
|
|
582
568
|
let argString = "";
|
|
583
569
|
if (nameString !== "") {
|