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