@flowscripter/dynamic-cli-framework 2.5.0 → 3.0.1
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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/src/command/MultiCommandCliHelpCommand.d.ts +4 -4
- package/dist/src/command/MultiCommandCliHelpCommand.d.ts.map +1 -1
- package/dist/src/command/MultiCommandCliHelpCommand.js +3 -3
- package/dist/src/runtime/command/CommandValidator.d.ts.map +1 -1
- package/dist/src/runtime/command/CommandValidator.js +14 -16
- package/dist/src/runtime/parser.d.ts +5 -5
- package/dist/src/runtime/parser.d.ts.map +1 -1
- package/dist/src/runtime/parser.js +2 -2
- package/dist/src/runtime/runner.d.ts.map +1 -1
- package/dist/src/runtime/values/ValuePopulationResult.d.ts +3 -3
- package/dist/src/runtime/values/ValuePopulationResult.d.ts.map +1 -1
- package/dist/src/runtime/values/argumentValueMerge.d.ts +2 -2
- package/dist/src/runtime/values/argumentValueMerge.d.ts.map +1 -1
- package/dist/src/runtime/values/argumentValueValidation.d.ts +4 -4
- package/dist/src/runtime/values/argumentValueValidation.d.ts.map +1 -1
- package/dist/src/runtime/values/argumentValueValidation.js +6 -6
- package/dist/src/runtime/values/globalCommandValuePopulation.d.ts +4 -4
- package/dist/src/runtime/values/globalCommandValuePopulation.d.ts.map +1 -1
- package/dist/src/runtime/values/globalCommandValuePopulation.js +5 -5
- package/dist/src/runtime/values/subCommandValuePopulation.d.ts +5 -5
- package/dist/src/runtime/values/subCommandValuePopulation.d.ts.map +1 -1
- package/dist/src/runtime/values/subCommandValuePopulation.js +8 -7
- package/dist/src/service/argumentPrompter/DefaultArgumentPrompterService.d.ts.map +1 -1
- package/dist/src/service/argumentPrompter/DefaultArgumentPrompterService.js +6 -6
- package/dist/src/service/banner/command/NoBannerCommand.d.ts +2 -2
- package/dist/src/service/banner/command/NoBannerCommand.d.ts.map +1 -1
- package/dist/src/service/banner/command/NoBannerCommand.js +2 -2
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts +2 -2
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts.map +1 -1
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.js +3 -3
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts +2 -2
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts.map +1 -1
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.js +3 -3
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts +6 -6
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts.map +1 -1
- package/dist/src/service/configuration/ConfigurationServiceProvider.js +4 -4
- package/dist/src/service/configuration/command/ConfigCommand.d.ts +2 -2
- package/dist/src/service/configuration/command/ConfigCommand.d.ts.map +1 -1
- package/dist/src/service/configuration/command/ConfigCommand.js +2 -2
- package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts +4 -4
- package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts.map +1 -1
- package/dist/src/service/plugin/command/PluginAddSubCommand.js +2 -2
- package/dist/src/service/plugin/command/PluginListSubCommand.d.ts +2 -2
- package/dist/src/service/plugin/command/PluginListSubCommand.d.ts.map +1 -1
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts +4 -4
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts.map +1 -1
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.js +2 -2
- package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts +4 -4
- package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts.map +1 -1
- package/dist/src/service/plugin/command/PluginSearchSubCommand.js +2 -2
- package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts +2 -2
- package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/DarkModeCommand.d.ts +2 -2
- package/dist/src/service/printer/command/DarkModeCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/DarkModeCommand.js +2 -2
- package/dist/src/service/printer/command/LogLevelCommand.d.ts +2 -2
- package/dist/src/service/printer/command/LogLevelCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/LogLevelCommand.js +2 -2
- package/dist/src/service/printer/command/NoColorCommand.d.ts +2 -2
- package/dist/src/service/printer/command/NoColorCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/NoColorCommand.js +2 -2
- package/dist/src/service/printer/command/NoHyperlinksCommand.d.ts +2 -2
- package/dist/src/service/printer/command/NoHyperlinksCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/NoHyperlinksCommand.js +2 -2
- package/dist/src/service/prompter/command/NoPromptCommand.d.ts +2 -2
- package/dist/src/service/prompter/command/NoPromptCommand.d.ts.map +1 -1
- package/dist/src/service/prompter/command/NoPromptCommand.js +2 -2
- package/dist/src/service/upgrade/DefaultUpgradeService.d.ts.map +1 -1
- package/dist/src/service/upgrade/DefaultUpgradeService.js +11 -1
- package/dist/src/service/upgrade/command/UpgradeSubCommand.d.ts +2 -2
- package/dist/src/service/upgrade/command/UpgradeSubCommand.d.ts.map +1 -1
- package/dist/src/service/upgrade/command/UpgradeSubCommand.js +3 -3
- package/dist/src/util/envVarHelper.d.ts +3 -3
- package/dist/src/util/envVarHelper.d.ts.map +1 -1
- package/dist/src/util/envVarHelper.js +9 -12
- package/dist/src/util/helpHelper.d.ts.map +1 -1
- package/dist/src/util/helpHelper.js +27 -28
- package/index.ts +7 -10
- package/package.json +2 -2
- package/src/command/MultiCommandCliHelpCommand.ts +7 -7
- package/src/runtime/command/CommandValidator.ts +17 -26
- package/src/runtime/parser.ts +8 -8
- package/src/runtime/runner.ts +16 -19
- package/src/runtime/values/ValuePopulationResult.ts +4 -4
- package/src/runtime/values/argumentValueMerge.ts +33 -50
- package/src/runtime/values/argumentValueValidation.ts +38 -52
- package/src/runtime/values/globalCommandValuePopulation.ts +7 -7
- package/src/runtime/values/subCommandValuePopulation.ts +42 -47
- package/src/service/argumentPrompter/DefaultArgumentPrompterService.ts +23 -26
- package/src/service/banner/command/NoBannerCommand.ts +3 -6
- package/src/service/completion/command/CompletionCompleteSubCommand.ts +4 -7
- package/src/service/completion/command/CompletionIntegrationSubCommand.ts +4 -7
- package/src/service/configuration/ConfigurationServiceProvider.ts +21 -21
- package/src/service/configuration/command/ConfigCommand.ts +3 -6
- package/src/service/plugin/command/PluginAddSubCommand.ts +4 -4
- package/src/service/plugin/command/PluginListSubCommand.ts +2 -2
- package/src/service/plugin/command/PluginRemoveSubCommand.ts +4 -4
- package/src/service/plugin/command/PluginSearchSubCommand.ts +4 -4
- package/src/service/plugin/command/PluginUpgradeSubCommand.ts +2 -2
- package/src/service/printer/command/DarkModeCommand.ts +3 -6
- package/src/service/printer/command/LogLevelCommand.ts +3 -6
- package/src/service/printer/command/NoColorCommand.ts +3 -6
- package/src/service/printer/command/NoHyperlinksCommand.ts +3 -6
- package/src/service/prompter/command/NoPromptCommand.ts +3 -6
- package/src/service/prompter/prompt/promptText.ts +2 -2
- package/src/service/upgrade/DefaultUpgradeService.ts +11 -1
- package/src/service/upgrade/command/UpgradeSubCommand.ts +4 -7
- package/src/util/envVarHelper.ts +23 -26
- package/src/util/helpHelper.ts +28 -36
package/src/runtime/runner.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { RunState } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
4
4
|
import type { CommandRegistry } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
5
|
import { isGlobalCommand, isSubCommand } from "./command/CommandTypeGuards.ts";
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
SingleValueType,
|
|
8
|
+
Values,
|
|
9
|
+
PopulatedSingleValueType,
|
|
10
|
+
PopulatedValues,
|
|
11
11
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
12
12
|
import getLogger from "../util/logger.ts";
|
|
13
13
|
import {
|
|
@@ -98,14 +98,11 @@ async function executeParsedCommand(
|
|
|
98
98
|
configurationServiceProvider.setCommandKeyValueScope(parseResult.command.name);
|
|
99
99
|
}
|
|
100
100
|
if (isSubCommand(parseResult.command)) {
|
|
101
|
-
await parseResult.command.execute(
|
|
102
|
-
context,
|
|
103
|
-
parseResult.populatedArgumentValues as ArgumentValues,
|
|
104
|
-
);
|
|
101
|
+
await parseResult.command.execute(context, parseResult.populatedArgumentValues as Values);
|
|
105
102
|
} else {
|
|
106
103
|
await (parseResult.command as GlobalCommand).execute(
|
|
107
104
|
context,
|
|
108
|
-
parseResult.populatedArgumentValues as
|
|
105
|
+
parseResult.populatedArgumentValues as SingleValueType,
|
|
109
106
|
);
|
|
110
107
|
}
|
|
111
108
|
if (
|
|
@@ -174,7 +171,7 @@ async function findAndExecuteGlobalModifierCommands(
|
|
|
174
171
|
: undefined;
|
|
175
172
|
const parseResult = parseGlobalCommandClause(
|
|
176
173
|
globalModifierCommandClause,
|
|
177
|
-
defaultArgumentValues as
|
|
174
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
178
175
|
);
|
|
179
176
|
|
|
180
177
|
if (parseResult.invalidArguments.length > 0) {
|
|
@@ -219,7 +216,7 @@ async function findAndExecuteGlobalModifierCommands(
|
|
|
219
216
|
command: globalModifierCommand,
|
|
220
217
|
potentialArgs: [],
|
|
221
218
|
},
|
|
222
|
-
defaultArgumentValues as
|
|
219
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
223
220
|
);
|
|
224
221
|
|
|
225
222
|
if (parseResult.invalidArguments.length > 0) {
|
|
@@ -300,12 +297,12 @@ async function findAndExecuteNonModifierCommand(
|
|
|
300
297
|
if (isGlobalCommand(scanResult.nonModifierCommandClause.command)) {
|
|
301
298
|
parseResult = parseGlobalCommandClause(
|
|
302
299
|
scanResult.nonModifierCommandClause,
|
|
303
|
-
defaultArgumentValues as
|
|
300
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
304
301
|
);
|
|
305
302
|
} else {
|
|
306
303
|
parseResult = parseSubCommandClause(
|
|
307
304
|
scanResult.nonModifierCommandClause,
|
|
308
|
-
defaultArgumentValues as
|
|
305
|
+
defaultArgumentValues as PopulatedValues,
|
|
309
306
|
);
|
|
310
307
|
}
|
|
311
308
|
|
|
@@ -345,7 +342,7 @@ async function findAndExecuteNonModifierCommand(
|
|
|
345
342
|
command: nonModifierCommand,
|
|
346
343
|
potentialArgs: [],
|
|
347
344
|
},
|
|
348
|
-
defaultArgumentValues as
|
|
345
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
349
346
|
);
|
|
350
347
|
} else {
|
|
351
348
|
parseResult = parseSubCommandClause(
|
|
@@ -353,7 +350,7 @@ async function findAndExecuteNonModifierCommand(
|
|
|
353
350
|
command: nonModifierCommand,
|
|
354
351
|
potentialArgs: [],
|
|
355
352
|
},
|
|
356
|
-
defaultArgumentValues as
|
|
353
|
+
defaultArgumentValues as PopulatedValues,
|
|
357
354
|
);
|
|
358
355
|
}
|
|
359
356
|
|
|
@@ -430,7 +427,7 @@ async function findAndExecuteDefaultNonModifierCommand(
|
|
|
430
427
|
command: defaultNonModifierCommand,
|
|
431
428
|
potentialArgs: [...argSequence],
|
|
432
429
|
},
|
|
433
|
-
defaultArgumentValues as
|
|
430
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
434
431
|
);
|
|
435
432
|
} else {
|
|
436
433
|
parseResult = parseSubCommandClause(
|
|
@@ -438,7 +435,7 @@ async function findAndExecuteDefaultNonModifierCommand(
|
|
|
438
435
|
command: defaultNonModifierCommand,
|
|
439
436
|
potentialArgs: [...argSequence],
|
|
440
437
|
},
|
|
441
|
-
defaultArgumentValues as
|
|
438
|
+
defaultArgumentValues as PopulatedValues,
|
|
442
439
|
);
|
|
443
440
|
}
|
|
444
441
|
|
|
@@ -470,7 +467,7 @@ async function findAndExecuteDefaultNonModifierCommand(
|
|
|
470
467
|
command: defaultNonModifierCommand,
|
|
471
468
|
potentialArgs: [],
|
|
472
469
|
},
|
|
473
|
-
defaultArgumentValues as
|
|
470
|
+
defaultArgumentValues as PopulatedSingleValueType,
|
|
474
471
|
);
|
|
475
472
|
} else {
|
|
476
473
|
parseResult = parseSubCommandClause(
|
|
@@ -478,7 +475,7 @@ async function findAndExecuteDefaultNonModifierCommand(
|
|
|
478
475
|
command: defaultNonModifierCommand,
|
|
479
476
|
potentialArgs: [],
|
|
480
477
|
},
|
|
481
|
-
defaultArgumentValues as
|
|
478
|
+
defaultArgumentValues as PopulatedValues,
|
|
482
479
|
);
|
|
483
480
|
}
|
|
484
481
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
PopulatedSingleValueType,
|
|
3
|
+
PopulatedValues,
|
|
4
4
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
5
5
|
import type { InvalidArgument } from "@flowscripter/dynamic-cli-framework-api";
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ export interface SubCommandValuePopulationResult extends ValuePopulationResult {
|
|
|
26
26
|
/**
|
|
27
27
|
* Populated argument values.
|
|
28
28
|
*/
|
|
29
|
-
readonly populatedArgumentValues:
|
|
29
|
+
readonly populatedArgumentValues: PopulatedValues;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -36,5 +36,5 @@ export interface GlobalCommandValuePopulationResult extends ValuePopulationResul
|
|
|
36
36
|
/**
|
|
37
37
|
* Populated argument value.
|
|
38
38
|
*/
|
|
39
|
-
readonly populatedArgumentValue:
|
|
39
|
+
readonly populatedArgumentValue: PopulatedSingleValueType;
|
|
40
40
|
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
SingleValueType,
|
|
3
|
+
Values,
|
|
4
|
+
PopulatedSingleValueType,
|
|
5
|
+
PopulatedValues,
|
|
6
|
+
PopulatedValueType,
|
|
7
7
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
8
8
|
import { MAXIMUM_ARGUMENT_ARRAY_SIZE } from "@flowscripter/dynamic-cli-framework-api";
|
|
9
9
|
import { MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH } from "@flowscripter/dynamic-cli-framework-api";
|
|
10
10
|
|
|
11
11
|
function doClone(
|
|
12
12
|
source:
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
| Array<
|
|
16
|
-
| Array<
|
|
13
|
+
| PopulatedValueType
|
|
14
|
+
| PopulatedValues
|
|
15
|
+
| Array<PopulatedValues | undefined>
|
|
16
|
+
| Array<PopulatedSingleValueType>,
|
|
17
17
|
nestingLevel: number,
|
|
18
|
-
):
|
|
19
|
-
| PopulatedArgumentValueType
|
|
20
|
-
| PopulatedArgumentValues
|
|
21
|
-
| Array<PopulatedArgumentValues>
|
|
22
|
-
| Array<PopulatedArgumentSingleValueType> {
|
|
18
|
+
): PopulatedValueType | PopulatedValues | Array<PopulatedValues> | Array<PopulatedSingleValueType> {
|
|
23
19
|
if (source === undefined) {
|
|
24
20
|
return source;
|
|
25
21
|
}
|
|
@@ -36,10 +32,10 @@ function doClone(
|
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
function arrayMerge(
|
|
39
|
-
override: Array<
|
|
40
|
-
base: Array<
|
|
35
|
+
override: Array<PopulatedSingleValueType> | Array<PopulatedValues | undefined>,
|
|
36
|
+
base: Array<PopulatedSingleValueType> | Array<PopulatedValues>,
|
|
41
37
|
nestingLevel: number,
|
|
42
|
-
): Array<
|
|
38
|
+
): Array<PopulatedSingleValueType> | Array<PopulatedValues> {
|
|
43
39
|
if (override.length > MAXIMUM_ARGUMENT_ARRAY_SIZE) {
|
|
44
40
|
throw new Error(`Maximum array size exceeded: ${override.length}`);
|
|
45
41
|
}
|
|
@@ -55,31 +51,28 @@ function arrayMerge(
|
|
|
55
51
|
);
|
|
56
52
|
}
|
|
57
53
|
if (index >= base.length) {
|
|
58
|
-
result.push(
|
|
59
|
-
doClone(argValue, nestingLevel) as PopulatedArgumentSingleValueType &
|
|
60
|
-
PopulatedArgumentValues,
|
|
61
|
-
);
|
|
54
|
+
result.push(doClone(argValue, nestingLevel) as PopulatedSingleValueType & PopulatedValues);
|
|
62
55
|
} else {
|
|
63
56
|
result[index] = doMerge(argValue, base[index], nestingLevel) as
|
|
64
|
-
|
|
|
65
|
-
|
|
|
57
|
+
| PopulatedSingleValueType
|
|
58
|
+
| PopulatedValues;
|
|
66
59
|
}
|
|
67
60
|
});
|
|
68
61
|
return result;
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
function objectMerge(
|
|
72
|
-
override:
|
|
73
|
-
base:
|
|
65
|
+
override: PopulatedValues,
|
|
66
|
+
base: PopulatedValues,
|
|
74
67
|
nestingLevel: number,
|
|
75
|
-
):
|
|
68
|
+
): PopulatedValues {
|
|
76
69
|
if (nestingLevel > MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH) {
|
|
77
70
|
throw new Error(`Maximum complex option nesting depth exceeded: ${nestingLevel}`);
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
nestingLevel++;
|
|
81
74
|
|
|
82
|
-
const result:
|
|
75
|
+
const result: PopulatedValues = {};
|
|
83
76
|
|
|
84
77
|
Object.keys(override).forEach((argName) => {
|
|
85
78
|
if (base[argName] === undefined) {
|
|
@@ -102,16 +95,10 @@ function objectMerge(
|
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
function doMerge(
|
|
105
|
-
override:
|
|
106
|
-
|
|
107
|
-
| PopulatedArgumentValueType
|
|
108
|
-
| Array<PopulatedArgumentValues | undefined>,
|
|
109
|
-
defaults:
|
|
110
|
-
| PopulatedArgumentValues
|
|
111
|
-
| PopulatedArgumentValueType
|
|
112
|
-
| Array<PopulatedArgumentValues | undefined>,
|
|
98
|
+
override: PopulatedValues | PopulatedValueType | Array<PopulatedValues | undefined>,
|
|
99
|
+
defaults: PopulatedValues | PopulatedValueType | Array<PopulatedValues | undefined>,
|
|
113
100
|
nestingLevel: number,
|
|
114
|
-
):
|
|
101
|
+
): PopulatedValues | PopulatedValueType | Array<PopulatedValues> {
|
|
115
102
|
if (defaults === undefined) {
|
|
116
103
|
throw new Error(
|
|
117
104
|
`Undefined value provided in merge: override = ${JSON.stringify(
|
|
@@ -123,15 +110,15 @@ function doMerge(
|
|
|
123
110
|
// check if we need to convert from single value to array
|
|
124
111
|
if (Array.isArray(override)) {
|
|
125
112
|
if (typeof defaults === "object") {
|
|
126
|
-
defaults = [defaults as
|
|
113
|
+
defaults = [defaults as Values];
|
|
127
114
|
} else {
|
|
128
|
-
defaults = [defaults as
|
|
115
|
+
defaults = [defaults as SingleValueType];
|
|
129
116
|
}
|
|
130
117
|
} else if (Array.isArray(defaults)) {
|
|
131
118
|
if (typeof override === "object") {
|
|
132
|
-
override = [override as
|
|
119
|
+
override = [override as PopulatedValues];
|
|
133
120
|
} else {
|
|
134
|
-
override = [override as
|
|
121
|
+
override = [override as PopulatedSingleValueType];
|
|
135
122
|
}
|
|
136
123
|
} // check if we need to convert from single non-string value to single string value
|
|
137
124
|
else if (
|
|
@@ -151,15 +138,11 @@ function doMerge(
|
|
|
151
138
|
|
|
152
139
|
// check if override is an array
|
|
153
140
|
if (Array.isArray(override)) {
|
|
154
|
-
return arrayMerge(
|
|
155
|
-
override,
|
|
156
|
-
defaults as Array<ArgumentValues> | Array<ArgumentSingleValueType>,
|
|
157
|
-
nestingLevel,
|
|
158
|
-
);
|
|
141
|
+
return arrayMerge(override, defaults as Array<Values> | Array<SingleValueType>, nestingLevel);
|
|
159
142
|
}
|
|
160
143
|
// check if override is an object
|
|
161
144
|
if (typeof override === "object") {
|
|
162
|
-
return objectMerge(override, defaults as
|
|
145
|
+
return objectMerge(override, defaults as Values, nestingLevel);
|
|
163
146
|
}
|
|
164
147
|
|
|
165
148
|
// check if override is undefined so we should use default
|
|
@@ -182,8 +165,8 @@ function doMerge(
|
|
|
182
165
|
* @param defaults the values to use unless they are overridden in `override`.
|
|
183
166
|
*/
|
|
184
167
|
export default function argumentValueMerge(
|
|
185
|
-
override:
|
|
186
|
-
defaults:
|
|
187
|
-
):
|
|
188
|
-
return doMerge(override, defaults, 0) as
|
|
168
|
+
override: PopulatedValues,
|
|
169
|
+
defaults: PopulatedValues,
|
|
170
|
+
): PopulatedValues {
|
|
171
|
+
return doMerge(override, defaults, 0) as PopulatedValues;
|
|
189
172
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@flowscripter/dynamic-cli-framework-api";
|
|
9
|
-
import {
|
|
10
|
-
ArgumentValueTypeName,
|
|
11
|
-
ComplexValueTypeName,
|
|
2
|
+
SingleValueType,
|
|
3
|
+
Values,
|
|
4
|
+
ValueType,
|
|
5
|
+
PopulatedSingleValueType,
|
|
6
|
+
PopulatedValues,
|
|
7
|
+
PopulatedValueType,
|
|
12
8
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
9
|
+
import { ValueTypeName, ComplexValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
13
10
|
import type { Positional } from "@flowscripter/dynamic-cli-framework-api";
|
|
14
11
|
import type { Option } from "@flowscripter/dynamic-cli-framework-api";
|
|
15
12
|
import type { ComplexOption } from "@flowscripter/dynamic-cli-framework-api";
|
|
@@ -25,15 +22,15 @@ interface ValidationResult {
|
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
interface SingleValueValidationResult extends ValidationResult {
|
|
28
|
-
validValue?:
|
|
25
|
+
validValue?: SingleValueType;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
interface ArrayValueValidationResult extends ValidationResult {
|
|
32
|
-
validValue?: Array<
|
|
29
|
+
validValue?: Array<SingleValueType | Values>;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
interface ObjectValueValidationResult extends ValidationResult {
|
|
36
|
-
validValue?:
|
|
33
|
+
validValue?: Values;
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
/**
|
|
@@ -44,7 +41,7 @@ interface ObjectValueValidationResult extends ValidationResult {
|
|
|
44
41
|
*/
|
|
45
42
|
function validatePrimitiveValue(
|
|
46
43
|
argument: Argument,
|
|
47
|
-
value:
|
|
44
|
+
value: PopulatedSingleValueType,
|
|
48
45
|
): SingleValueValidationResult {
|
|
49
46
|
let convertedValue;
|
|
50
47
|
|
|
@@ -60,7 +57,7 @@ function validatePrimitiveValue(
|
|
|
60
57
|
// type check and conversion
|
|
61
58
|
let castValue: string | undefined;
|
|
62
59
|
switch (argument.type) {
|
|
63
|
-
case
|
|
60
|
+
case ValueTypeName.BOOLEAN:
|
|
64
61
|
if (value === true || value === false) {
|
|
65
62
|
convertedValue = value;
|
|
66
63
|
break;
|
|
@@ -80,7 +77,7 @@ function validatePrimitiveValue(
|
|
|
80
77
|
}
|
|
81
78
|
convertedValue = castValue === "true";
|
|
82
79
|
break;
|
|
83
|
-
case
|
|
80
|
+
case ValueTypeName.INTEGER:
|
|
84
81
|
if (!Number.isInteger(Number(value))) {
|
|
85
82
|
return {
|
|
86
83
|
invalidArgument: {
|
|
@@ -92,7 +89,7 @@ function validatePrimitiveValue(
|
|
|
92
89
|
}
|
|
93
90
|
convertedValue = Number(value);
|
|
94
91
|
break;
|
|
95
|
-
case
|
|
92
|
+
case ValueTypeName.NUMBER:
|
|
96
93
|
if (!Number.isFinite(Number(value))) {
|
|
97
94
|
return {
|
|
98
95
|
invalidArgument: {
|
|
@@ -104,7 +101,7 @@ function validatePrimitiveValue(
|
|
|
104
101
|
}
|
|
105
102
|
convertedValue = Number(value);
|
|
106
103
|
break;
|
|
107
|
-
case
|
|
104
|
+
case ValueTypeName.STRING:
|
|
108
105
|
default:
|
|
109
106
|
convertedValue = String(value);
|
|
110
107
|
break;
|
|
@@ -116,7 +113,7 @@ function validatePrimitiveValue(
|
|
|
116
113
|
let searchValue = convertedValue;
|
|
117
114
|
let allowableValues = argument.allowableValues;
|
|
118
115
|
|
|
119
|
-
if (argument.type ===
|
|
116
|
+
if (argument.type === ValueTypeName.STRING && argument.isCaseInsensitive) {
|
|
120
117
|
searchValue = (convertedValue as string).toLowerCase();
|
|
121
118
|
allowableValues = argument.allowableValues.map((v) => (v as string).toLowerCase());
|
|
122
119
|
}
|
|
@@ -159,9 +156,9 @@ function validatePrimitiveValue(
|
|
|
159
156
|
|
|
160
157
|
function validateArrayValue(
|
|
161
158
|
subCommandArgument: SubCommandArgument | ComplexOption,
|
|
162
|
-
arrayValue: Array<
|
|
159
|
+
arrayValue: Array<PopulatedSingleValueType | PopulatedValues | undefined>,
|
|
163
160
|
): ArrayValueValidationResult {
|
|
164
|
-
const convertedArrayValue: Array<
|
|
161
|
+
const convertedArrayValue: Array<SingleValueType | Values> = [];
|
|
165
162
|
|
|
166
163
|
for (let i = 0; i < arrayValue.length; i += 1) {
|
|
167
164
|
const singleValue = arrayValue[i];
|
|
@@ -253,9 +250,9 @@ function validateArrayValue(
|
|
|
253
250
|
|
|
254
251
|
function validateObjectValue(
|
|
255
252
|
argument: ComplexOption,
|
|
256
|
-
objectValue:
|
|
253
|
+
objectValue: PopulatedValues,
|
|
257
254
|
): ObjectValueValidationResult {
|
|
258
|
-
const convertedObjectValue:
|
|
255
|
+
const convertedObjectValue: Values = {};
|
|
259
256
|
|
|
260
257
|
for (let i = 0; i < argument.properties.length; i++) {
|
|
261
258
|
const propertyArg = argument.properties[i]!;
|
|
@@ -307,7 +304,7 @@ function validateObjectValue(
|
|
|
307
304
|
}
|
|
308
305
|
validationResult = validateObjectValue(
|
|
309
306
|
propertyArg as ComplexOption,
|
|
310
|
-
propertyValue as
|
|
307
|
+
propertyValue as PopulatedValues,
|
|
311
308
|
);
|
|
312
309
|
} // if not array and not object, then must be primitive
|
|
313
310
|
else {
|
|
@@ -326,9 +323,9 @@ function validateObjectValue(
|
|
|
326
323
|
}
|
|
327
324
|
if (validationResult.validValue !== undefined) {
|
|
328
325
|
convertedObjectValue[propertyArg.name] = validationResult.validValue as
|
|
329
|
-
|
|
|
330
|
-
|
|
|
331
|
-
| Array<
|
|
326
|
+
| ValueType
|
|
327
|
+
| Values
|
|
328
|
+
| Array<Values>;
|
|
332
329
|
}
|
|
333
330
|
// fast fail
|
|
334
331
|
if (validationResult.invalidArgument !== undefined) {
|
|
@@ -365,14 +362,11 @@ function validateObjectValue(
|
|
|
365
362
|
|
|
366
363
|
function doSubCommandArgumentValidation(
|
|
367
364
|
argument: SubCommandArgument | ComplexOption,
|
|
368
|
-
value:
|
|
369
|
-
| PopulatedArgumentValueType
|
|
370
|
-
| PopulatedArgumentValues
|
|
371
|
-
| Array<PopulatedArgumentValues | undefined>,
|
|
365
|
+
value: PopulatedValueType | PopulatedValues | Array<PopulatedValues | undefined>,
|
|
372
366
|
isArray: boolean,
|
|
373
367
|
isOptional: boolean,
|
|
374
368
|
invalidArguments: Array<InvalidArgument>,
|
|
375
|
-
):
|
|
369
|
+
): PopulatedValueType | PopulatedValues | Array<PopulatedValues> {
|
|
376
370
|
// if there is a value, check if it is valid
|
|
377
371
|
if (value !== undefined) {
|
|
378
372
|
let validationResult;
|
|
@@ -439,23 +433,20 @@ function doSubCommandArgumentValidation(
|
|
|
439
433
|
}
|
|
440
434
|
if (argument.validate && validationResult.validValue !== undefined) {
|
|
441
435
|
const customError = argument.validate(
|
|
442
|
-
validationResult.validValue as
|
|
436
|
+
validationResult.validValue as ValueType | Values | Array<Values>,
|
|
443
437
|
);
|
|
444
438
|
if (customError !== undefined) {
|
|
445
439
|
invalidArguments.push({
|
|
446
440
|
argument,
|
|
447
441
|
name: argument.name,
|
|
448
|
-
value: validationResult.validValue as
|
|
442
|
+
value: validationResult.validValue as PopulatedValueType,
|
|
449
443
|
reason: InvalidArgumentReason.CUSTOM_VALIDATION,
|
|
450
444
|
message: customError,
|
|
451
445
|
});
|
|
452
446
|
return undefined;
|
|
453
447
|
}
|
|
454
448
|
}
|
|
455
|
-
return validationResult.validValue as
|
|
456
|
-
| PopulatedArgumentValueType
|
|
457
|
-
| PopulatedArgumentValues
|
|
458
|
-
| undefined;
|
|
449
|
+
return validationResult.validValue as PopulatedValueType | PopulatedValues | undefined;
|
|
459
450
|
}
|
|
460
451
|
|
|
461
452
|
// if there is no value, check if it was optional
|
|
@@ -478,12 +469,9 @@ function doSubCommandArgumentValidation(
|
|
|
478
469
|
*/
|
|
479
470
|
export function validateOptionValue(
|
|
480
471
|
option: Option | ComplexOption,
|
|
481
|
-
value:
|
|
482
|
-
| PopulatedArgumentValueType
|
|
483
|
-
| PopulatedArgumentValues
|
|
484
|
-
| Array<PopulatedArgumentValues | undefined>,
|
|
472
|
+
value: PopulatedValueType | PopulatedValues | Array<PopulatedValues | undefined>,
|
|
485
473
|
invalidArguments: Array<InvalidArgument>,
|
|
486
|
-
):
|
|
474
|
+
): PopulatedValueType | PopulatedValues | Array<PopulatedValues> {
|
|
487
475
|
return doSubCommandArgumentValidation(
|
|
488
476
|
option,
|
|
489
477
|
value,
|
|
@@ -502,16 +490,16 @@ export function validateOptionValue(
|
|
|
502
490
|
*/
|
|
503
491
|
export function validatePositionalValue(
|
|
504
492
|
positional: Positional,
|
|
505
|
-
value:
|
|
493
|
+
value: PopulatedValueType,
|
|
506
494
|
invalidArguments: Array<InvalidArgument>,
|
|
507
|
-
):
|
|
495
|
+
): PopulatedValueType {
|
|
508
496
|
return doSubCommandArgumentValidation(
|
|
509
497
|
positional,
|
|
510
498
|
value,
|
|
511
499
|
positional.isVarargMultiple || false,
|
|
512
500
|
positional.isVarargOptional || false,
|
|
513
501
|
invalidArguments,
|
|
514
|
-
) as
|
|
502
|
+
) as PopulatedValueType;
|
|
515
503
|
}
|
|
516
504
|
|
|
517
505
|
/**
|
|
@@ -524,9 +512,9 @@ export function validatePositionalValue(
|
|
|
524
512
|
*/
|
|
525
513
|
export function validateGlobalCommandArgumentValue(
|
|
526
514
|
globalCommand: GlobalCommand,
|
|
527
|
-
value:
|
|
515
|
+
value: PopulatedSingleValueType,
|
|
528
516
|
invalidArguments: Array<InvalidArgument>,
|
|
529
|
-
):
|
|
517
|
+
): PopulatedSingleValueType {
|
|
530
518
|
// if this function is called it is because the argument is defined
|
|
531
519
|
const globalCommandArgument = globalCommand.argument!;
|
|
532
520
|
|
|
@@ -553,9 +541,7 @@ export function validateGlobalCommandArgumentValue(
|
|
|
553
541
|
}
|
|
554
542
|
|
|
555
543
|
if (globalCommandArgument.validate && validationResult.validValue !== undefined) {
|
|
556
|
-
const customError = globalCommandArgument.validate(
|
|
557
|
-
validationResult.validValue as ArgumentValueType,
|
|
558
|
-
);
|
|
544
|
+
const customError = globalCommandArgument.validate(validationResult.validValue as ValueType);
|
|
559
545
|
if (customError !== undefined) {
|
|
560
546
|
invalidArguments.push({
|
|
561
547
|
argument: globalCommandArgument,
|
|
@@ -567,7 +553,7 @@ export function validateGlobalCommandArgumentValue(
|
|
|
567
553
|
return undefined;
|
|
568
554
|
}
|
|
569
555
|
}
|
|
570
|
-
return validationResult.validValue as
|
|
556
|
+
return validationResult.validValue as PopulatedSingleValueType;
|
|
571
557
|
}
|
|
572
558
|
|
|
573
559
|
// if there is no value, check if it was optional
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { GlobalCommand } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
2
|
import type { GlobalCommandValuePopulationResult } from "./ValuePopulationResult.ts";
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import { ValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
4
|
+
import type { PopulatedSingleValueType } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
5
|
import getLogger from "../../util/logger.ts";
|
|
6
6
|
import { InvalidArgumentReason } from "@flowscripter/dynamic-cli-framework-api";
|
|
7
7
|
|
|
8
8
|
const logger = getLogger("globalCommandValuePopulation");
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Attempt to populate a {@link
|
|
11
|
+
* Attempt to populate a {@link ValueType} for the provided {@link GlobalCommand} using the provided potential args.
|
|
12
12
|
*
|
|
13
|
-
* @param globalCommand the {@link GlobalCommand} for which {@link
|
|
13
|
+
* @param globalCommand the {@link GlobalCommand} for which {@link Values} values should be populated.
|
|
14
14
|
* @param potentialArgs the potential args to use for population.
|
|
15
15
|
* @param defaultValue optional default value to use for population before parsing the provided arguments.
|
|
16
16
|
*/
|
|
17
17
|
export default function populateGlobalCommandValue(
|
|
18
18
|
globalCommand: GlobalCommand,
|
|
19
19
|
potentialArgs: ReadonlyArray<string>,
|
|
20
|
-
defaultValue:
|
|
20
|
+
defaultValue: PopulatedSingleValueType,
|
|
21
21
|
): GlobalCommandValuePopulationResult {
|
|
22
22
|
logger.debug(() => {
|
|
23
23
|
const message = `Populating value for global command: '${globalCommand.name}' using potential args: ${potentialArgs.join(
|
|
@@ -43,7 +43,7 @@ export default function populateGlobalCommandValue(
|
|
|
43
43
|
const firstPotentialArg = potentialArgs[0];
|
|
44
44
|
|
|
45
45
|
// don't use potentialArg if it cannot be a boolean value...
|
|
46
|
-
if (argument.type ===
|
|
46
|
+
if (argument.type === ValueTypeName.BOOLEAN) {
|
|
47
47
|
const firstPotentialArgLower = firstPotentialArg!.toLowerCase();
|
|
48
48
|
|
|
49
49
|
if (firstPotentialArgLower !== "true" && firstPotentialArgLower !== "false") {
|
|
@@ -59,7 +59,7 @@ export default function populateGlobalCommandValue(
|
|
|
59
59
|
unusedArgs = potentialArgs.slice(1);
|
|
60
60
|
} // check if argument type is boolean and therefore command being specified is an implicit value of true
|
|
61
61
|
else if (
|
|
62
|
-
argument.type ===
|
|
62
|
+
argument.type === ValueTypeName.BOOLEAN &&
|
|
63
63
|
(populatedArgumentValue === undefined || argument.defaultValue === false)
|
|
64
64
|
) {
|
|
65
65
|
return {
|