@flowscripter/dynamic-cli-framework 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -22,61 +22,38 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
22
22
|
test("Option argument", () => {
|
|
23
23
|
const command: SubCommand = {
|
|
24
24
|
name: "command",
|
|
25
|
-
options: [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
name: "foo",
|
|
28
|
+
type: ArgumentValueTypeName.STRING,
|
|
29
|
+
shortAlias: "f",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
30
32
|
positionals: [],
|
|
31
|
-
execute: async (): Promise<void> => {
|
|
32
|
-
},
|
|
33
|
+
execute: async (): Promise<void> => {},
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
let result = populateSubCommandValues(
|
|
36
|
-
command,
|
|
37
|
-
["--foo", "bar"],
|
|
38
|
-
undefined,
|
|
39
|
-
);
|
|
36
|
+
let result = populateSubCommandValues(command, ["--foo", "bar"], undefined);
|
|
40
37
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
41
38
|
expect(result.invalidArgument).toBeUndefined();
|
|
42
39
|
|
|
43
|
-
result = populateSubCommandValues(
|
|
44
|
-
command,
|
|
45
|
-
["--foo=bar"],
|
|
46
|
-
undefined,
|
|
47
|
-
);
|
|
40
|
+
result = populateSubCommandValues(command, ["--foo=bar"], undefined);
|
|
48
41
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
49
42
|
expect(result.invalidArgument).toBeUndefined();
|
|
50
43
|
|
|
51
|
-
result = populateSubCommandValues(
|
|
52
|
-
command,
|
|
53
|
-
["-f", "bar"],
|
|
54
|
-
undefined,
|
|
55
|
-
);
|
|
44
|
+
result = populateSubCommandValues(command, ["-f", "bar"], undefined);
|
|
56
45
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
57
46
|
expect(result.invalidArgument).toBeUndefined();
|
|
58
47
|
|
|
59
|
-
result = populateSubCommandValues(
|
|
60
|
-
command,
|
|
61
|
-
["-f=bar"],
|
|
62
|
-
undefined,
|
|
63
|
-
);
|
|
48
|
+
result = populateSubCommandValues(command, ["-f=bar"], undefined);
|
|
64
49
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
65
50
|
expect(result.invalidArgument).toBeUndefined();
|
|
66
51
|
|
|
67
|
-
result = populateSubCommandValues(
|
|
68
|
-
command,
|
|
69
|
-
["--foo", "goo=1 and goo=2"],
|
|
70
|
-
undefined,
|
|
71
|
-
);
|
|
52
|
+
result = populateSubCommandValues(command, ["--foo", "goo=1 and goo=2"], undefined);
|
|
72
53
|
expectExtractResult(result, { foo: "goo=1 and goo=2" }, []);
|
|
73
54
|
expect(result.invalidArgument).toBeUndefined();
|
|
74
55
|
|
|
75
|
-
result = populateSubCommandValues(
|
|
76
|
-
command,
|
|
77
|
-
["--foo=goo=1 and goo=2"],
|
|
78
|
-
undefined,
|
|
79
|
-
);
|
|
56
|
+
result = populateSubCommandValues(command, ["--foo=goo=1 and goo=2"], undefined);
|
|
80
57
|
expectExtractResult(result, { foo: "goo=1 and goo=2" }, []);
|
|
81
58
|
expect(result.invalidArgument).toBeUndefined();
|
|
82
59
|
});
|
|
@@ -84,101 +61,86 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
84
61
|
test("Option types", () => {
|
|
85
62
|
let command: SubCommand = {
|
|
86
63
|
name: "command",
|
|
87
|
-
options: [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
options: [
|
|
65
|
+
{
|
|
66
|
+
name: "foo",
|
|
67
|
+
shortAlias: "f",
|
|
68
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
92
71
|
positionals: [],
|
|
93
|
-
execute: async (): Promise<void> => {
|
|
94
|
-
},
|
|
72
|
+
execute: async (): Promise<void> => {},
|
|
95
73
|
};
|
|
96
74
|
|
|
97
|
-
let result = populateSubCommandValues(
|
|
98
|
-
command,
|
|
99
|
-
["--foo", "1.1"],
|
|
100
|
-
undefined,
|
|
101
|
-
);
|
|
75
|
+
let result = populateSubCommandValues(command, ["--foo", "1.1"], undefined);
|
|
102
76
|
expectExtractResult(result, { foo: "1.1" }, []);
|
|
103
77
|
expect(result.invalidArgument).toBeUndefined();
|
|
104
78
|
|
|
105
79
|
command = {
|
|
106
80
|
name: "command",
|
|
107
|
-
options: [
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
81
|
+
options: [
|
|
82
|
+
{
|
|
83
|
+
name: "foo",
|
|
84
|
+
shortAlias: "f",
|
|
85
|
+
type: ArgumentValueTypeName.INTEGER,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
112
88
|
positionals: [],
|
|
113
|
-
execute: async (): Promise<void> => {
|
|
114
|
-
},
|
|
89
|
+
execute: async (): Promise<void> => {},
|
|
115
90
|
};
|
|
116
91
|
|
|
117
|
-
result = populateSubCommandValues(
|
|
118
|
-
command,
|
|
119
|
-
["-f", "1"],
|
|
120
|
-
undefined,
|
|
121
|
-
);
|
|
92
|
+
result = populateSubCommandValues(command, ["-f", "1"], undefined);
|
|
122
93
|
expectExtractResult(result, { foo: "1" }, []);
|
|
123
94
|
expect(result.invalidArgument).toBeUndefined();
|
|
124
95
|
|
|
125
96
|
command = {
|
|
126
97
|
name: "command",
|
|
127
|
-
options: [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
98
|
+
options: [
|
|
99
|
+
{
|
|
100
|
+
name: "foo",
|
|
101
|
+
shortAlias: "f",
|
|
102
|
+
type: ArgumentValueTypeName.SECRET,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
132
105
|
positionals: [],
|
|
133
|
-
execute: async (): Promise<void> => {
|
|
134
|
-
},
|
|
106
|
+
execute: async (): Promise<void> => {},
|
|
135
107
|
};
|
|
136
108
|
|
|
137
|
-
result = populateSubCommandValues(
|
|
138
|
-
command,
|
|
139
|
-
["-f", "xxx"],
|
|
140
|
-
undefined,
|
|
141
|
-
);
|
|
109
|
+
result = populateSubCommandValues(command, ["-f", "xxx"], undefined);
|
|
142
110
|
expectExtractResult(result, { foo: "xxx" }, []);
|
|
143
111
|
expect(result.invalidArgument).toBeUndefined();
|
|
144
112
|
|
|
145
113
|
command = {
|
|
146
114
|
name: "command",
|
|
147
|
-
options: [
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
115
|
+
options: [
|
|
116
|
+
{
|
|
117
|
+
name: "foo",
|
|
118
|
+
shortAlias: "f",
|
|
119
|
+
type: ArgumentValueTypeName.STRING,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
152
122
|
positionals: [],
|
|
153
|
-
execute: async (): Promise<void> => {
|
|
154
|
-
},
|
|
123
|
+
execute: async (): Promise<void> => {},
|
|
155
124
|
};
|
|
156
125
|
|
|
157
|
-
result = populateSubCommandValues(
|
|
158
|
-
command,
|
|
159
|
-
["-f", "bar"],
|
|
160
|
-
undefined,
|
|
161
|
-
);
|
|
126
|
+
result = populateSubCommandValues(command, ["-f", "bar"], undefined);
|
|
162
127
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
163
128
|
expect(result.invalidArgument).toBeUndefined();
|
|
164
129
|
|
|
165
130
|
command = {
|
|
166
131
|
name: "command",
|
|
167
|
-
options: [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
132
|
+
options: [
|
|
133
|
+
{
|
|
134
|
+
name: "foo",
|
|
135
|
+
shortAlias: "f",
|
|
136
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
172
139
|
positionals: [],
|
|
173
|
-
execute: async (): Promise<void> => {
|
|
174
|
-
},
|
|
140
|
+
execute: async (): Promise<void> => {},
|
|
175
141
|
};
|
|
176
142
|
|
|
177
|
-
result = populateSubCommandValues(
|
|
178
|
-
command,
|
|
179
|
-
["-f"],
|
|
180
|
-
undefined,
|
|
181
|
-
);
|
|
143
|
+
result = populateSubCommandValues(command, ["-f"], undefined);
|
|
182
144
|
expectExtractResult(result, { foo: "true" }, []);
|
|
183
145
|
expect(result.invalidArgument).toBeUndefined();
|
|
184
146
|
});
|
|
@@ -186,54 +148,35 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
186
148
|
test("Option array", () => {
|
|
187
149
|
const command: SubCommand = {
|
|
188
150
|
name: "command",
|
|
189
|
-
options: [
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
151
|
+
options: [
|
|
152
|
+
{
|
|
153
|
+
name: "foo",
|
|
154
|
+
type: ArgumentValueTypeName.STRING,
|
|
155
|
+
shortAlias: "f",
|
|
156
|
+
isArray: true,
|
|
157
|
+
},
|
|
158
|
+
],
|
|
195
159
|
positionals: [],
|
|
196
|
-
execute: async (): Promise<void> => {
|
|
197
|
-
},
|
|
160
|
+
execute: async (): Promise<void> => {},
|
|
198
161
|
};
|
|
199
162
|
|
|
200
|
-
let result = populateSubCommandValues(
|
|
201
|
-
command,
|
|
202
|
-
["--foo", "bar"],
|
|
203
|
-
undefined,
|
|
204
|
-
);
|
|
163
|
+
let result = populateSubCommandValues(command, ["--foo", "bar"], undefined);
|
|
205
164
|
expectExtractResult(result, { foo: ["bar"] }, []);
|
|
206
165
|
expect(result.invalidArgument).toBeUndefined();
|
|
207
166
|
|
|
208
|
-
result = populateSubCommandValues(
|
|
209
|
-
command,
|
|
210
|
-
["--foo", "bar", "--foo", "bar"],
|
|
211
|
-
undefined,
|
|
212
|
-
);
|
|
167
|
+
result = populateSubCommandValues(command, ["--foo", "bar", "--foo", "bar"], undefined);
|
|
213
168
|
expectExtractResult(result, { foo: ["bar", "bar"] }, []);
|
|
214
169
|
expect(result.invalidArgument).toBeUndefined();
|
|
215
170
|
|
|
216
|
-
result = populateSubCommandValues(
|
|
217
|
-
command,
|
|
218
|
-
["--foo=bar", "--foo", "bar"],
|
|
219
|
-
undefined,
|
|
220
|
-
);
|
|
171
|
+
result = populateSubCommandValues(command, ["--foo=bar", "--foo", "bar"], undefined);
|
|
221
172
|
expectExtractResult(result, { foo: ["bar", "bar"] }, []);
|
|
222
173
|
expect(result.invalidArgument).toBeUndefined();
|
|
223
174
|
|
|
224
|
-
result = populateSubCommandValues(
|
|
225
|
-
command,
|
|
226
|
-
["--foo=bar", "-f", "bar"],
|
|
227
|
-
undefined,
|
|
228
|
-
);
|
|
175
|
+
result = populateSubCommandValues(command, ["--foo=bar", "-f", "bar"], undefined);
|
|
229
176
|
expectExtractResult(result, { foo: ["bar", "bar"] }, []);
|
|
230
177
|
expect(result.invalidArgument).toBeUndefined();
|
|
231
178
|
|
|
232
|
-
result = populateSubCommandValues(
|
|
233
|
-
command,
|
|
234
|
-
["--foo=bar", "-f=bar"],
|
|
235
|
-
undefined,
|
|
236
|
-
);
|
|
179
|
+
result = populateSubCommandValues(command, ["--foo=bar", "-f=bar"], undefined);
|
|
237
180
|
expectExtractResult(result, { foo: ["bar", "bar"] }, []);
|
|
238
181
|
expect(result.invalidArgument).toBeUndefined();
|
|
239
182
|
});
|
|
@@ -241,58 +184,53 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
241
184
|
test("Option argument configured value is overridden by arg", () => {
|
|
242
185
|
let command: SubCommand = {
|
|
243
186
|
name: "command",
|
|
244
|
-
options: [
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
187
|
+
options: [
|
|
188
|
+
{
|
|
189
|
+
name: "foo",
|
|
190
|
+
type: ArgumentValueTypeName.STRING,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
248
193
|
positionals: [],
|
|
249
|
-
execute: async (): Promise<void> => {
|
|
250
|
-
},
|
|
194
|
+
execute: async (): Promise<void> => {},
|
|
251
195
|
};
|
|
252
196
|
|
|
253
|
-
let result = populateSubCommandValues(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
{ foo: "nope" },
|
|
257
|
-
);
|
|
197
|
+
let result = populateSubCommandValues(command, ["--foo", "bar"], {
|
|
198
|
+
foo: "nope",
|
|
199
|
+
});
|
|
258
200
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
259
201
|
expect(result.invalidArgument).toBeUndefined();
|
|
260
202
|
|
|
261
203
|
command = {
|
|
262
204
|
name: "command",
|
|
263
|
-
options: [
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
205
|
+
options: [
|
|
206
|
+
{
|
|
207
|
+
name: "foo",
|
|
208
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
267
211
|
positionals: [],
|
|
268
|
-
execute: async (): Promise<void> => {
|
|
269
|
-
},
|
|
212
|
+
execute: async (): Promise<void> => {},
|
|
270
213
|
};
|
|
271
214
|
|
|
272
|
-
result = populateSubCommandValues(
|
|
273
|
-
command,
|
|
274
|
-
["--foo", "1"],
|
|
275
|
-
{ foo: 2 },
|
|
276
|
-
);
|
|
215
|
+
result = populateSubCommandValues(command, ["--foo", "1"], { foo: 2 });
|
|
277
216
|
expectExtractResult(result, { foo: "1" }, []);
|
|
278
217
|
expect(result.invalidArgument).toBeUndefined();
|
|
279
218
|
|
|
280
219
|
command = {
|
|
281
220
|
name: "command",
|
|
282
|
-
options: [
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
221
|
+
options: [
|
|
222
|
+
{
|
|
223
|
+
name: "foo",
|
|
224
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
286
227
|
positionals: [],
|
|
287
|
-
execute: async (): Promise<void> => {
|
|
288
|
-
},
|
|
228
|
+
execute: async (): Promise<void> => {},
|
|
289
229
|
};
|
|
290
230
|
|
|
291
|
-
result = populateSubCommandValues(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
{ foo: false },
|
|
295
|
-
);
|
|
231
|
+
result = populateSubCommandValues(command, ["--foo", "true"], {
|
|
232
|
+
foo: false,
|
|
233
|
+
});
|
|
296
234
|
expectExtractResult(result, { foo: "true" }, []);
|
|
297
235
|
expect(result.invalidArgument).toBeUndefined();
|
|
298
236
|
});
|
|
@@ -300,61 +238,52 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
300
238
|
test("Option argument default value is overridden by configured value", () => {
|
|
301
239
|
let command: SubCommand = {
|
|
302
240
|
name: "command",
|
|
303
|
-
options: [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
241
|
+
options: [
|
|
242
|
+
{
|
|
243
|
+
name: "foo",
|
|
244
|
+
type: ArgumentValueTypeName.STRING,
|
|
245
|
+
defaultValue: "nope",
|
|
246
|
+
},
|
|
247
|
+
],
|
|
308
248
|
positionals: [],
|
|
309
|
-
execute: async (): Promise<void> => {
|
|
310
|
-
},
|
|
249
|
+
execute: async (): Promise<void> => {},
|
|
311
250
|
};
|
|
312
251
|
|
|
313
|
-
let result = populateSubCommandValues(
|
|
314
|
-
command,
|
|
315
|
-
[],
|
|
316
|
-
{ foo: "bar" },
|
|
317
|
-
);
|
|
252
|
+
let result = populateSubCommandValues(command, [], { foo: "bar" });
|
|
318
253
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
319
254
|
expect(result.invalidArgument).toBeUndefined();
|
|
320
255
|
|
|
321
256
|
command = {
|
|
322
257
|
name: "command",
|
|
323
|
-
options: [
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
258
|
+
options: [
|
|
259
|
+
{
|
|
260
|
+
name: "foo",
|
|
261
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
262
|
+
defaultValue: 2,
|
|
263
|
+
},
|
|
264
|
+
],
|
|
328
265
|
positionals: [],
|
|
329
|
-
execute: async (): Promise<void> => {
|
|
330
|
-
},
|
|
266
|
+
execute: async (): Promise<void> => {},
|
|
331
267
|
};
|
|
332
268
|
|
|
333
|
-
result = populateSubCommandValues(
|
|
334
|
-
command,
|
|
335
|
-
[],
|
|
336
|
-
{ foo: 1 },
|
|
337
|
-
);
|
|
269
|
+
result = populateSubCommandValues(command, [], { foo: 1 });
|
|
338
270
|
expectExtractResult(result, { foo: 1 }, []);
|
|
339
271
|
expect(result.invalidArgument).toBeUndefined();
|
|
340
272
|
|
|
341
273
|
command = {
|
|
342
274
|
name: "command",
|
|
343
|
-
options: [
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
275
|
+
options: [
|
|
276
|
+
{
|
|
277
|
+
name: "foo",
|
|
278
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
279
|
+
defaultValue: false,
|
|
280
|
+
},
|
|
281
|
+
],
|
|
348
282
|
positionals: [],
|
|
349
|
-
execute: async (): Promise<void> => {
|
|
350
|
-
},
|
|
283
|
+
execute: async (): Promise<void> => {},
|
|
351
284
|
};
|
|
352
285
|
|
|
353
|
-
result = populateSubCommandValues(
|
|
354
|
-
command,
|
|
355
|
-
[],
|
|
356
|
-
{ foo: true },
|
|
357
|
-
);
|
|
286
|
+
result = populateSubCommandValues(command, [], { foo: true });
|
|
358
287
|
expectExtractResult(result, { foo: true }, []);
|
|
359
288
|
expect(result.invalidArgument).toBeUndefined();
|
|
360
289
|
});
|
|
@@ -362,61 +291,52 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
362
291
|
test("Option argument default value is overridden by arg", () => {
|
|
363
292
|
let command: SubCommand = {
|
|
364
293
|
name: "command",
|
|
365
|
-
options: [
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
294
|
+
options: [
|
|
295
|
+
{
|
|
296
|
+
name: "foo",
|
|
297
|
+
type: ArgumentValueTypeName.STRING,
|
|
298
|
+
defaultValue: "nope",
|
|
299
|
+
},
|
|
300
|
+
],
|
|
370
301
|
positionals: [],
|
|
371
|
-
execute: async (): Promise<void> => {
|
|
372
|
-
},
|
|
302
|
+
execute: async (): Promise<void> => {},
|
|
373
303
|
};
|
|
374
304
|
|
|
375
|
-
let result = populateSubCommandValues(
|
|
376
|
-
command,
|
|
377
|
-
["--foo", "bar"],
|
|
378
|
-
undefined,
|
|
379
|
-
);
|
|
305
|
+
let result = populateSubCommandValues(command, ["--foo", "bar"], undefined);
|
|
380
306
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
381
307
|
expect(result.invalidArgument).toBeUndefined();
|
|
382
308
|
|
|
383
309
|
command = {
|
|
384
310
|
name: "command",
|
|
385
|
-
options: [
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
311
|
+
options: [
|
|
312
|
+
{
|
|
313
|
+
name: "foo",
|
|
314
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
315
|
+
defaultValue: 2,
|
|
316
|
+
},
|
|
317
|
+
],
|
|
390
318
|
positionals: [],
|
|
391
|
-
execute: async (): Promise<void> => {
|
|
392
|
-
},
|
|
319
|
+
execute: async (): Promise<void> => {},
|
|
393
320
|
};
|
|
394
321
|
|
|
395
|
-
result = populateSubCommandValues(
|
|
396
|
-
command,
|
|
397
|
-
["--foo", "1"],
|
|
398
|
-
undefined,
|
|
399
|
-
);
|
|
322
|
+
result = populateSubCommandValues(command, ["--foo", "1"], undefined);
|
|
400
323
|
expectExtractResult(result, { foo: "1" }, []);
|
|
401
324
|
expect(result.invalidArgument).toBeUndefined();
|
|
402
325
|
|
|
403
326
|
command = {
|
|
404
327
|
name: "command",
|
|
405
|
-
options: [
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
328
|
+
options: [
|
|
329
|
+
{
|
|
330
|
+
name: "foo",
|
|
331
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
332
|
+
defaultValue: true,
|
|
333
|
+
},
|
|
334
|
+
],
|
|
410
335
|
positionals: [],
|
|
411
|
-
execute: async (): Promise<void> => {
|
|
412
|
-
},
|
|
336
|
+
execute: async (): Promise<void> => {},
|
|
413
337
|
};
|
|
414
338
|
|
|
415
|
-
result = populateSubCommandValues(
|
|
416
|
-
command,
|
|
417
|
-
["--foo", "false"],
|
|
418
|
-
undefined,
|
|
419
|
-
);
|
|
339
|
+
result = populateSubCommandValues(command, ["--foo", "false"], undefined);
|
|
420
340
|
expectExtractResult(result, { foo: "false" }, []);
|
|
421
341
|
expect(result.invalidArgument).toBeUndefined();
|
|
422
342
|
});
|
|
@@ -424,58 +344,49 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
424
344
|
test("Option argument configured value is used if no arg provided", () => {
|
|
425
345
|
let command: SubCommand = {
|
|
426
346
|
name: "command",
|
|
427
|
-
options: [
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
347
|
+
options: [
|
|
348
|
+
{
|
|
349
|
+
name: "foo",
|
|
350
|
+
type: ArgumentValueTypeName.STRING,
|
|
351
|
+
},
|
|
352
|
+
],
|
|
431
353
|
positionals: [],
|
|
432
|
-
execute: async (): Promise<void> => {
|
|
433
|
-
},
|
|
354
|
+
execute: async (): Promise<void> => {},
|
|
434
355
|
};
|
|
435
356
|
|
|
436
|
-
let result = populateSubCommandValues(
|
|
437
|
-
command,
|
|
438
|
-
[],
|
|
439
|
-
{ foo: "bar" },
|
|
440
|
-
);
|
|
357
|
+
let result = populateSubCommandValues(command, [], { foo: "bar" });
|
|
441
358
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
442
359
|
expect(result.invalidArgument).toBeUndefined();
|
|
443
360
|
|
|
444
361
|
command = {
|
|
445
362
|
name: "command",
|
|
446
|
-
options: [
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
363
|
+
options: [
|
|
364
|
+
{
|
|
365
|
+
name: "foo",
|
|
366
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
367
|
+
},
|
|
368
|
+
],
|
|
450
369
|
positionals: [],
|
|
451
|
-
execute: async (): Promise<void> => {
|
|
452
|
-
},
|
|
370
|
+
execute: async (): Promise<void> => {},
|
|
453
371
|
};
|
|
454
372
|
|
|
455
|
-
result = populateSubCommandValues(
|
|
456
|
-
command,
|
|
457
|
-
[],
|
|
458
|
-
{ foo: 1 },
|
|
459
|
-
);
|
|
373
|
+
result = populateSubCommandValues(command, [], { foo: 1 });
|
|
460
374
|
expectExtractResult(result, { foo: 1 }, []);
|
|
461
375
|
expect(result.invalidArgument).toBeUndefined();
|
|
462
376
|
|
|
463
377
|
command = {
|
|
464
378
|
name: "command",
|
|
465
|
-
options: [
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
379
|
+
options: [
|
|
380
|
+
{
|
|
381
|
+
name: "foo",
|
|
382
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
383
|
+
},
|
|
384
|
+
],
|
|
469
385
|
positionals: [],
|
|
470
|
-
execute: async (): Promise<void> => {
|
|
471
|
-
},
|
|
386
|
+
execute: async (): Promise<void> => {},
|
|
472
387
|
};
|
|
473
388
|
|
|
474
|
-
result = populateSubCommandValues(
|
|
475
|
-
command,
|
|
476
|
-
[],
|
|
477
|
-
{ foo: false },
|
|
478
|
-
);
|
|
389
|
+
result = populateSubCommandValues(command, [], { foo: false });
|
|
479
390
|
expectExtractResult(result, { foo: false }, []);
|
|
480
391
|
expect(result.invalidArgument).toBeUndefined();
|
|
481
392
|
});
|
|
@@ -483,75 +394,64 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
483
394
|
test("Two options", () => {
|
|
484
395
|
let command: SubCommand = {
|
|
485
396
|
name: "command",
|
|
486
|
-
options: [
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
397
|
+
options: [
|
|
398
|
+
{
|
|
399
|
+
name: "foo",
|
|
400
|
+
type: ArgumentValueTypeName.STRING,
|
|
401
|
+
isArray: false,
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
name: "goo",
|
|
405
|
+
type: ArgumentValueTypeName.STRING,
|
|
406
|
+
},
|
|
407
|
+
],
|
|
494
408
|
positionals: [],
|
|
495
|
-
execute: async (): Promise<void> => {
|
|
496
|
-
},
|
|
409
|
+
execute: async (): Promise<void> => {},
|
|
497
410
|
};
|
|
498
411
|
|
|
499
|
-
let result = populateSubCommandValues(
|
|
500
|
-
command,
|
|
501
|
-
["--foo", "bar", "--goo=gar"],
|
|
502
|
-
undefined,
|
|
503
|
-
);
|
|
412
|
+
let result = populateSubCommandValues(command, ["--foo", "bar", "--goo=gar"], undefined);
|
|
504
413
|
expectExtractResult(result, { foo: "bar", goo: "gar" }, []);
|
|
505
414
|
expect(result.invalidArgument).toBeUndefined();
|
|
506
415
|
|
|
507
416
|
command = {
|
|
508
417
|
name: "command",
|
|
509
|
-
options: [
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
418
|
+
options: [
|
|
419
|
+
{
|
|
420
|
+
name: "foo",
|
|
421
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
422
|
+
isArray: false,
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: "goo",
|
|
426
|
+
type: ArgumentValueTypeName.STRING,
|
|
427
|
+
},
|
|
428
|
+
],
|
|
517
429
|
positionals: [],
|
|
518
|
-
execute: async (): Promise<void> => {
|
|
519
|
-
},
|
|
430
|
+
execute: async (): Promise<void> => {},
|
|
520
431
|
};
|
|
521
432
|
|
|
522
|
-
result = populateSubCommandValues(
|
|
523
|
-
command,
|
|
524
|
-
["--foo", "--goo=gar"],
|
|
525
|
-
undefined,
|
|
526
|
-
);
|
|
433
|
+
result = populateSubCommandValues(command, ["--foo", "--goo=gar"], undefined);
|
|
527
434
|
expectExtractResult(result, { foo: "true", goo: "gar" }, []);
|
|
528
435
|
expect(result.invalidArgument).toBeUndefined();
|
|
529
436
|
|
|
530
437
|
command = {
|
|
531
438
|
name: "command",
|
|
532
|
-
options: [
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
439
|
+
options: [
|
|
440
|
+
{
|
|
441
|
+
name: "foo",
|
|
442
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
443
|
+
isArray: true,
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
name: "goo",
|
|
447
|
+
type: ArgumentValueTypeName.STRING,
|
|
448
|
+
},
|
|
449
|
+
],
|
|
540
450
|
positionals: [],
|
|
541
|
-
execute: async (): Promise<void> => {
|
|
542
|
-
},
|
|
451
|
+
execute: async (): Promise<void> => {},
|
|
543
452
|
};
|
|
544
453
|
|
|
545
|
-
result = populateSubCommandValues(
|
|
546
|
-
command,
|
|
547
|
-
[
|
|
548
|
-
"--foo",
|
|
549
|
-
"--foo",
|
|
550
|
-
"false",
|
|
551
|
-
"--goo=gar",
|
|
552
|
-
],
|
|
553
|
-
undefined,
|
|
554
|
-
);
|
|
454
|
+
result = populateSubCommandValues(command, ["--foo", "--foo", "false", "--goo=gar"], undefined);
|
|
555
455
|
expectExtractResult(result, { foo: ["true", "false"], goo: "gar" }, []);
|
|
556
456
|
expect(result.invalidArgument).toBeUndefined();
|
|
557
457
|
});
|
|
@@ -559,74 +459,64 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
559
459
|
test("Interleaved option arrays", () => {
|
|
560
460
|
const command: SubCommand = {
|
|
561
461
|
name: "command",
|
|
562
|
-
options: [
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
462
|
+
options: [
|
|
463
|
+
{
|
|
464
|
+
name: "foo",
|
|
465
|
+
type: ArgumentValueTypeName.STRING,
|
|
466
|
+
isArray: true,
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
name: "goo",
|
|
470
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
471
|
+
isArray: true,
|
|
472
|
+
shortAlias: "g",
|
|
473
|
+
},
|
|
474
|
+
],
|
|
572
475
|
positionals: [],
|
|
573
|
-
execute: async (): Promise<void> => {
|
|
574
|
-
},
|
|
476
|
+
execute: async (): Promise<void> => {},
|
|
575
477
|
};
|
|
576
478
|
|
|
577
479
|
let result = populateSubCommandValues(
|
|
578
480
|
command,
|
|
579
|
-
[
|
|
580
|
-
"--foo",
|
|
581
|
-
"bar1",
|
|
582
|
-
"--goo=true",
|
|
583
|
-
"--foo",
|
|
584
|
-
"bar2",
|
|
585
|
-
"--goo=false",
|
|
586
|
-
],
|
|
481
|
+
["--foo", "bar1", "--goo=true", "--foo", "bar2", "--goo=false"],
|
|
587
482
|
undefined,
|
|
588
483
|
);
|
|
589
484
|
expectExtractResult(
|
|
590
485
|
result,
|
|
591
|
-
{
|
|
486
|
+
{
|
|
487
|
+
foo: ["bar1", "bar2"],
|
|
488
|
+
goo: ["true", "false"],
|
|
489
|
+
},
|
|
592
490
|
[],
|
|
593
491
|
);
|
|
594
492
|
expect(result.invalidArgument).toBeUndefined();
|
|
595
493
|
|
|
596
494
|
result = populateSubCommandValues(
|
|
597
495
|
command,
|
|
598
|
-
[
|
|
599
|
-
"--foo",
|
|
600
|
-
"bar1",
|
|
601
|
-
"--goo=true",
|
|
602
|
-
"--goo=false",
|
|
603
|
-
"--foo",
|
|
604
|
-
"bar2",
|
|
605
|
-
],
|
|
496
|
+
["--foo", "bar1", "--goo=true", "--goo=false", "--foo", "bar2"],
|
|
606
497
|
undefined,
|
|
607
498
|
);
|
|
608
499
|
expectExtractResult(
|
|
609
500
|
result,
|
|
610
|
-
{
|
|
501
|
+
{
|
|
502
|
+
foo: ["bar1", "bar2"],
|
|
503
|
+
goo: ["true", "false"],
|
|
504
|
+
},
|
|
611
505
|
[],
|
|
612
506
|
);
|
|
613
507
|
expect(result.invalidArgument).toBeUndefined();
|
|
614
508
|
|
|
615
509
|
result = populateSubCommandValues(
|
|
616
510
|
command,
|
|
617
|
-
[
|
|
618
|
-
"--foo",
|
|
619
|
-
"bar1",
|
|
620
|
-
"-g",
|
|
621
|
-
"--foo",
|
|
622
|
-
"bar2",
|
|
623
|
-
"-g=false",
|
|
624
|
-
],
|
|
511
|
+
["--foo", "bar1", "-g", "--foo", "bar2", "-g=false"],
|
|
625
512
|
undefined,
|
|
626
513
|
);
|
|
627
514
|
expectExtractResult(
|
|
628
515
|
result,
|
|
629
|
-
{
|
|
516
|
+
{
|
|
517
|
+
foo: ["bar1", "bar2"],
|
|
518
|
+
goo: ["true", "false"],
|
|
519
|
+
},
|
|
630
520
|
[],
|
|
631
521
|
);
|
|
632
522
|
expect(result.invalidArgument).toBeUndefined();
|
|
@@ -635,28 +525,21 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
635
525
|
test("Unknown option name", () => {
|
|
636
526
|
const command: SubCommand = {
|
|
637
527
|
name: "command",
|
|
638
|
-
options: [
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
528
|
+
options: [
|
|
529
|
+
{
|
|
530
|
+
name: "foo",
|
|
531
|
+
type: ArgumentValueTypeName.STRING,
|
|
532
|
+
},
|
|
533
|
+
],
|
|
642
534
|
positionals: [],
|
|
643
|
-
execute: async (): Promise<void> => {
|
|
644
|
-
},
|
|
535
|
+
execute: async (): Promise<void> => {},
|
|
645
536
|
};
|
|
646
537
|
|
|
647
|
-
let result = populateSubCommandValues(
|
|
648
|
-
command,
|
|
649
|
-
["--goo=moo"],
|
|
650
|
-
undefined,
|
|
651
|
-
);
|
|
538
|
+
let result = populateSubCommandValues(command, ["--goo=moo"], undefined);
|
|
652
539
|
expectExtractResult(result, {}, ["--goo=moo"]);
|
|
653
540
|
expect(result.invalidArgument).toBeUndefined();
|
|
654
541
|
|
|
655
|
-
result = populateSubCommandValues(
|
|
656
|
-
command,
|
|
657
|
-
["--goo", "moo"],
|
|
658
|
-
undefined,
|
|
659
|
-
);
|
|
542
|
+
result = populateSubCommandValues(command, ["--goo", "moo"], undefined);
|
|
660
543
|
expectExtractResult(result, {}, ["--goo", "moo"]);
|
|
661
544
|
expect(result.invalidArgument).toBeUndefined();
|
|
662
545
|
});
|
|
@@ -664,48 +547,33 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
664
547
|
test("Illegal option syntax", () => {
|
|
665
548
|
const command: SubCommand = {
|
|
666
549
|
name: "command",
|
|
667
|
-
options: [
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
550
|
+
options: [
|
|
551
|
+
{
|
|
552
|
+
name: "foo",
|
|
553
|
+
shortAlias: "f",
|
|
554
|
+
type: ArgumentValueTypeName.STRING,
|
|
555
|
+
},
|
|
556
|
+
],
|
|
672
557
|
positionals: [],
|
|
673
|
-
execute: async (): Promise<void> => {
|
|
674
|
-
},
|
|
558
|
+
execute: async (): Promise<void> => {},
|
|
675
559
|
};
|
|
676
560
|
|
|
677
|
-
let result = populateSubCommandValues(
|
|
678
|
-
command,
|
|
679
|
-
["-foo=moo"],
|
|
680
|
-
undefined,
|
|
681
|
-
);
|
|
561
|
+
let result = populateSubCommandValues(command, ["-foo=moo"], undefined);
|
|
682
562
|
expectExtractResult(result, {}, ["-foo=moo"]);
|
|
683
563
|
expect(result.invalidArgument).toBeUndefined();
|
|
684
564
|
|
|
685
|
-
result = populateSubCommandValues(
|
|
686
|
-
command,
|
|
687
|
-
["--f", "moo"],
|
|
688
|
-
undefined,
|
|
689
|
-
);
|
|
565
|
+
result = populateSubCommandValues(command, ["--f", "moo"], undefined);
|
|
690
566
|
expectExtractResult(result, {}, ["--f", "moo"]);
|
|
691
567
|
expect(result.invalidArgument).toBeUndefined();
|
|
692
568
|
|
|
693
|
-
result = populateSubCommandValues(
|
|
694
|
-
command,
|
|
695
|
-
["--foo=", "moo"],
|
|
696
|
-
undefined,
|
|
697
|
-
);
|
|
569
|
+
result = populateSubCommandValues(command, ["--foo=", "moo"], undefined);
|
|
698
570
|
expectExtractResult(result, {}, ["moo"]);
|
|
699
571
|
expect(result.invalidArgument).toEqual({
|
|
700
572
|
name: "foo",
|
|
701
573
|
reason: InvalidArgumentReason.MISSING_VALUE,
|
|
702
574
|
});
|
|
703
575
|
|
|
704
|
-
result = populateSubCommandValues(
|
|
705
|
-
command,
|
|
706
|
-
["-f=", "moo"],
|
|
707
|
-
undefined,
|
|
708
|
-
);
|
|
576
|
+
result = populateSubCommandValues(command, ["-f=", "moo"], undefined);
|
|
709
577
|
expectExtractResult(result, {}, ["moo"]);
|
|
710
578
|
expect(result.invalidArgument).toEqual({
|
|
711
579
|
name: "f",
|
|
@@ -717,41 +585,36 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
717
585
|
let command: SubCommand = {
|
|
718
586
|
name: "command",
|
|
719
587
|
options: [],
|
|
720
|
-
positionals: [
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
588
|
+
positionals: [
|
|
589
|
+
{
|
|
590
|
+
name: "foo",
|
|
591
|
+
type: ArgumentValueTypeName.STRING,
|
|
592
|
+
},
|
|
593
|
+
],
|
|
594
|
+
execute: async (): Promise<void> => {},
|
|
726
595
|
};
|
|
727
596
|
|
|
728
|
-
let result = populateSubCommandValues(
|
|
729
|
-
command,
|
|
730
|
-
["bar"],
|
|
731
|
-
undefined,
|
|
732
|
-
);
|
|
597
|
+
let result = populateSubCommandValues(command, ["bar"], undefined);
|
|
733
598
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
734
599
|
expect(result.invalidArgument).toBeUndefined();
|
|
735
600
|
|
|
736
601
|
command = {
|
|
737
602
|
name: "command",
|
|
738
603
|
options: [],
|
|
739
|
-
positionals: [
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
604
|
+
positionals: [
|
|
605
|
+
{
|
|
606
|
+
name: "foo",
|
|
607
|
+
type: ArgumentValueTypeName.STRING,
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: "bar",
|
|
611
|
+
type: ArgumentValueTypeName.STRING,
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
execute: async (): Promise<void> => {},
|
|
748
615
|
};
|
|
749
616
|
|
|
750
|
-
result = populateSubCommandValues(
|
|
751
|
-
command,
|
|
752
|
-
["foo", "bar"],
|
|
753
|
-
undefined,
|
|
754
|
-
);
|
|
617
|
+
result = populateSubCommandValues(command, ["foo", "bar"], undefined);
|
|
755
618
|
expectExtractResult(result, { foo: "foo", bar: "bar" }, []);
|
|
756
619
|
expect(result.invalidArgument).toBeUndefined();
|
|
757
620
|
});
|
|
@@ -760,55 +623,46 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
760
623
|
let command: SubCommand = {
|
|
761
624
|
name: "command",
|
|
762
625
|
options: [],
|
|
763
|
-
positionals: [
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
626
|
+
positionals: [
|
|
627
|
+
{
|
|
628
|
+
name: "foo",
|
|
629
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
630
|
+
},
|
|
631
|
+
],
|
|
632
|
+
execute: async (): Promise<void> => {},
|
|
769
633
|
};
|
|
770
634
|
|
|
771
|
-
let result = populateSubCommandValues(
|
|
772
|
-
command,
|
|
773
|
-
["1"],
|
|
774
|
-
undefined,
|
|
775
|
-
);
|
|
635
|
+
let result = populateSubCommandValues(command, ["1"], undefined);
|
|
776
636
|
expectExtractResult(result, { foo: "1" }, []);
|
|
777
637
|
expect(result.invalidArgument).toBeUndefined();
|
|
778
638
|
|
|
779
639
|
command = {
|
|
780
640
|
name: "command",
|
|
781
641
|
options: [],
|
|
782
|
-
positionals: [
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
642
|
+
positionals: [
|
|
643
|
+
{
|
|
644
|
+
name: "foo",
|
|
645
|
+
type: ArgumentValueTypeName.STRING,
|
|
646
|
+
},
|
|
647
|
+
],
|
|
648
|
+
execute: async (): Promise<void> => {},
|
|
788
649
|
};
|
|
789
|
-
result = populateSubCommandValues(
|
|
790
|
-
command,
|
|
791
|
-
["bar"],
|
|
792
|
-
undefined,
|
|
793
|
-
);
|
|
650
|
+
result = populateSubCommandValues(command, ["bar"], undefined);
|
|
794
651
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
795
652
|
expect(result.invalidArgument).toBeUndefined();
|
|
796
653
|
|
|
797
654
|
command = {
|
|
798
655
|
name: "command",
|
|
799
656
|
options: [],
|
|
800
|
-
positionals: [
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
657
|
+
positionals: [
|
|
658
|
+
{
|
|
659
|
+
name: "foo",
|
|
660
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
661
|
+
},
|
|
662
|
+
],
|
|
663
|
+
execute: async (): Promise<void> => {},
|
|
806
664
|
};
|
|
807
|
-
result = populateSubCommandValues(
|
|
808
|
-
command,
|
|
809
|
-
["true"],
|
|
810
|
-
undefined,
|
|
811
|
-
);
|
|
665
|
+
result = populateSubCommandValues(command, ["true"], undefined);
|
|
812
666
|
expectExtractResult(result, { foo: "true" }, []);
|
|
813
667
|
expect(result.invalidArgument).toBeUndefined();
|
|
814
668
|
});
|
|
@@ -817,22 +671,20 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
817
671
|
const command: SubCommand = {
|
|
818
672
|
name: "command",
|
|
819
673
|
options: [],
|
|
820
|
-
positionals: [
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
674
|
+
positionals: [
|
|
675
|
+
{
|
|
676
|
+
name: "foo1",
|
|
677
|
+
type: ArgumentValueTypeName.STRING,
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
name: "foo2",
|
|
681
|
+
type: ArgumentValueTypeName.STRING,
|
|
682
|
+
},
|
|
683
|
+
],
|
|
684
|
+
execute: async (): Promise<void> => {},
|
|
829
685
|
};
|
|
830
686
|
|
|
831
|
-
const result = populateSubCommandValues(
|
|
832
|
-
command,
|
|
833
|
-
["f1", "f2"],
|
|
834
|
-
undefined,
|
|
835
|
-
);
|
|
687
|
+
const result = populateSubCommandValues(command, ["f1", "f2"], undefined);
|
|
836
688
|
expectExtractResult(result, { foo1: "f1", foo2: "f2" }, []);
|
|
837
689
|
expect(result.invalidArgument).toBeUndefined();
|
|
838
690
|
});
|
|
@@ -841,29 +693,22 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
841
693
|
const command: SubCommand = {
|
|
842
694
|
name: "command",
|
|
843
695
|
options: [],
|
|
844
|
-
positionals: [
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
696
|
+
positionals: [
|
|
697
|
+
{
|
|
698
|
+
name: "foo",
|
|
699
|
+
type: ArgumentValueTypeName.STRING,
|
|
700
|
+
isVarargMultiple: true,
|
|
701
|
+
isVarargOptional: true,
|
|
702
|
+
},
|
|
703
|
+
],
|
|
704
|
+
execute: async (): Promise<void> => {},
|
|
852
705
|
};
|
|
853
706
|
|
|
854
|
-
let result = populateSubCommandValues(
|
|
855
|
-
command,
|
|
856
|
-
["bar", "bar"],
|
|
857
|
-
undefined,
|
|
858
|
-
);
|
|
707
|
+
let result = populateSubCommandValues(command, ["bar", "bar"], undefined);
|
|
859
708
|
expectExtractResult(result, { foo: ["bar", "bar"] }, []);
|
|
860
709
|
expect(result.invalidArgument).toBeUndefined();
|
|
861
710
|
|
|
862
|
-
result = populateSubCommandValues(
|
|
863
|
-
command,
|
|
864
|
-
["bar"],
|
|
865
|
-
undefined,
|
|
866
|
-
);
|
|
711
|
+
result = populateSubCommandValues(command, ["bar"], undefined);
|
|
867
712
|
expectExtractResult(result, { foo: ["bar"] }, []);
|
|
868
713
|
expect(result.invalidArgument).toBeUndefined();
|
|
869
714
|
|
|
@@ -876,48 +721,34 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
876
721
|
const command: SubCommand = {
|
|
877
722
|
name: "command",
|
|
878
723
|
options: [],
|
|
879
|
-
positionals: [
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
724
|
+
positionals: [
|
|
725
|
+
{
|
|
726
|
+
name: "foo",
|
|
727
|
+
type: ArgumentValueTypeName.STRING,
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
name: "bar",
|
|
731
|
+
type: ArgumentValueTypeName.STRING,
|
|
732
|
+
isVarargMultiple: true,
|
|
733
|
+
isVarargOptional: true,
|
|
734
|
+
},
|
|
735
|
+
],
|
|
736
|
+
execute: async (): Promise<void> => {},
|
|
890
737
|
};
|
|
891
738
|
|
|
892
|
-
let result = populateSubCommandValues(
|
|
893
|
-
command,
|
|
894
|
-
["foo"],
|
|
895
|
-
undefined,
|
|
896
|
-
);
|
|
739
|
+
let result = populateSubCommandValues(command, ["foo"], undefined);
|
|
897
740
|
expectExtractResult(result, { foo: "foo" }, []);
|
|
898
741
|
expect(result.invalidArgument).toBeUndefined();
|
|
899
742
|
|
|
900
|
-
result = populateSubCommandValues(
|
|
901
|
-
command,
|
|
902
|
-
["foo", "bar"],
|
|
903
|
-
undefined,
|
|
904
|
-
);
|
|
743
|
+
result = populateSubCommandValues(command, ["foo", "bar"], undefined);
|
|
905
744
|
expectExtractResult(result, { foo: "foo", bar: ["bar"] }, []);
|
|
906
745
|
expect(result.invalidArgument).toBeUndefined();
|
|
907
746
|
|
|
908
|
-
result = populateSubCommandValues(
|
|
909
|
-
command,
|
|
910
|
-
["foo", "bar", "bar"],
|
|
911
|
-
undefined,
|
|
912
|
-
);
|
|
747
|
+
result = populateSubCommandValues(command, ["foo", "bar", "bar"], undefined);
|
|
913
748
|
expectExtractResult(result, { foo: "foo", bar: ["bar", "bar"] }, []);
|
|
914
749
|
expect(result.invalidArgument).toBeUndefined();
|
|
915
750
|
|
|
916
|
-
result = populateSubCommandValues(
|
|
917
|
-
command,
|
|
918
|
-
["foo"],
|
|
919
|
-
undefined,
|
|
920
|
-
);
|
|
751
|
+
result = populateSubCommandValues(command, ["foo"], undefined);
|
|
921
752
|
expectExtractResult(result, { foo: "foo" }, []);
|
|
922
753
|
expect(result.invalidArgument).toBeUndefined();
|
|
923
754
|
});
|
|
@@ -925,294 +756,269 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
925
756
|
test("String options either side of positionals", () => {
|
|
926
757
|
const command: SubCommand = {
|
|
927
758
|
name: "command",
|
|
928
|
-
options: [
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
759
|
+
options: [
|
|
760
|
+
{
|
|
761
|
+
name: "goo1",
|
|
762
|
+
type: ArgumentValueTypeName.STRING,
|
|
763
|
+
shortAlias: "1",
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
name: "goo2",
|
|
767
|
+
type: ArgumentValueTypeName.STRING,
|
|
768
|
+
shortAlias: "2",
|
|
769
|
+
},
|
|
770
|
+
],
|
|
771
|
+
positionals: [
|
|
772
|
+
{
|
|
773
|
+
name: "foo1",
|
|
774
|
+
type: ArgumentValueTypeName.STRING,
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
name: "foo2",
|
|
778
|
+
type: ArgumentValueTypeName.STRING,
|
|
779
|
+
},
|
|
780
|
+
],
|
|
781
|
+
execute: async (): Promise<void> => {},
|
|
946
782
|
};
|
|
947
783
|
|
|
948
784
|
let result = populateSubCommandValues(
|
|
949
785
|
command,
|
|
950
|
-
[
|
|
951
|
-
"--goo1=g1",
|
|
952
|
-
"f1",
|
|
953
|
-
"f2",
|
|
954
|
-
"--goo2=g2",
|
|
955
|
-
],
|
|
786
|
+
["--goo1=g1", "f1", "f2", "--goo2=g2"],
|
|
956
787
|
undefined,
|
|
957
788
|
);
|
|
958
|
-
expectExtractResult(
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
789
|
+
expectExtractResult(
|
|
790
|
+
result,
|
|
791
|
+
{
|
|
792
|
+
goo1: "g1",
|
|
793
|
+
goo2: "g2",
|
|
794
|
+
foo1: "f1",
|
|
795
|
+
foo2: "f2",
|
|
796
|
+
},
|
|
797
|
+
[],
|
|
798
|
+
);
|
|
964
799
|
expect(result.invalidArgument).toBeUndefined();
|
|
965
800
|
|
|
966
801
|
result = populateSubCommandValues(
|
|
967
802
|
command,
|
|
968
|
-
[
|
|
969
|
-
"--goo1",
|
|
970
|
-
"g1",
|
|
971
|
-
"f1",
|
|
972
|
-
"f2",
|
|
973
|
-
"--goo2",
|
|
974
|
-
"g2",
|
|
975
|
-
],
|
|
803
|
+
["--goo1", "g1", "f1", "f2", "--goo2", "g2"],
|
|
976
804
|
undefined,
|
|
977
805
|
);
|
|
978
|
-
expectExtractResult(
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
806
|
+
expectExtractResult(
|
|
807
|
+
result,
|
|
808
|
+
{
|
|
809
|
+
goo1: "g1",
|
|
810
|
+
goo2: "g2",
|
|
811
|
+
foo1: "f1",
|
|
812
|
+
foo2: "f2",
|
|
813
|
+
},
|
|
814
|
+
[],
|
|
815
|
+
);
|
|
984
816
|
expect(result.invalidArgument).toBeUndefined();
|
|
985
817
|
|
|
986
|
-
result = populateSubCommandValues(
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
"g1",
|
|
991
|
-
"
|
|
992
|
-
"
|
|
993
|
-
"
|
|
994
|
-
|
|
995
|
-
],
|
|
996
|
-
undefined,
|
|
818
|
+
result = populateSubCommandValues(command, ["-1", "g1", "f1", "f2", "-2", "g2"], undefined);
|
|
819
|
+
expectExtractResult(
|
|
820
|
+
result,
|
|
821
|
+
{
|
|
822
|
+
goo1: "g1",
|
|
823
|
+
goo2: "g2",
|
|
824
|
+
foo1: "f1",
|
|
825
|
+
foo2: "f2",
|
|
826
|
+
},
|
|
827
|
+
[],
|
|
997
828
|
);
|
|
998
|
-
expectExtractResult(result, {
|
|
999
|
-
goo1: "g1",
|
|
1000
|
-
goo2: "g2",
|
|
1001
|
-
foo1: "f1",
|
|
1002
|
-
foo2: "f2",
|
|
1003
|
-
}, []);
|
|
1004
829
|
expect(result.invalidArgument).toBeUndefined();
|
|
1005
830
|
});
|
|
1006
831
|
|
|
1007
832
|
test("Boolean options either side of positionals", () => {
|
|
1008
833
|
const command: SubCommand = {
|
|
1009
834
|
name: "command",
|
|
1010
|
-
options: [
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
835
|
+
options: [
|
|
836
|
+
{
|
|
837
|
+
name: "goo1",
|
|
838
|
+
shortAlias: "1",
|
|
839
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
name: "goo2",
|
|
843
|
+
shortAlias: "2",
|
|
844
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
845
|
+
},
|
|
846
|
+
],
|
|
847
|
+
positionals: [
|
|
848
|
+
{
|
|
849
|
+
name: "foo1",
|
|
850
|
+
type: ArgumentValueTypeName.STRING,
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
name: "foo2",
|
|
854
|
+
type: ArgumentValueTypeName.STRING,
|
|
855
|
+
},
|
|
856
|
+
],
|
|
857
|
+
execute: async (): Promise<void> => {},
|
|
1028
858
|
};
|
|
1029
859
|
|
|
1030
|
-
let result = populateSubCommandValues(
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
"
|
|
1035
|
-
"
|
|
1036
|
-
"
|
|
1037
|
-
|
|
1038
|
-
|
|
860
|
+
let result = populateSubCommandValues(command, ["--goo1", "f1", "f2", "--goo2"], undefined);
|
|
861
|
+
expectExtractResult(
|
|
862
|
+
result,
|
|
863
|
+
{
|
|
864
|
+
goo1: "true",
|
|
865
|
+
goo2: "true",
|
|
866
|
+
foo1: "f1",
|
|
867
|
+
foo2: "f2",
|
|
868
|
+
},
|
|
869
|
+
[],
|
|
1039
870
|
);
|
|
1040
|
-
expectExtractResult(result, {
|
|
1041
|
-
goo1: "true",
|
|
1042
|
-
goo2: "true",
|
|
1043
|
-
foo1: "f1",
|
|
1044
|
-
foo2: "f2",
|
|
1045
|
-
}, []);
|
|
1046
871
|
expect(result.invalidArgument).toBeUndefined();
|
|
1047
872
|
|
|
1048
873
|
result = populateSubCommandValues(
|
|
1049
874
|
command,
|
|
1050
|
-
[
|
|
1051
|
-
"--goo1",
|
|
1052
|
-
"true",
|
|
1053
|
-
"f1",
|
|
1054
|
-
"f2",
|
|
1055
|
-
"--goo2",
|
|
1056
|
-
"false",
|
|
1057
|
-
],
|
|
875
|
+
["--goo1", "true", "f1", "f2", "--goo2", "false"],
|
|
1058
876
|
undefined,
|
|
1059
877
|
);
|
|
1060
|
-
expectExtractResult(
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
878
|
+
expectExtractResult(
|
|
879
|
+
result,
|
|
880
|
+
{
|
|
881
|
+
goo1: "true",
|
|
882
|
+
goo2: "false",
|
|
883
|
+
foo1: "f1",
|
|
884
|
+
foo2: "f2",
|
|
885
|
+
},
|
|
886
|
+
[],
|
|
887
|
+
);
|
|
1066
888
|
expect(result.invalidArgument).toBeUndefined();
|
|
1067
889
|
|
|
1068
890
|
result = populateSubCommandValues(
|
|
1069
891
|
command,
|
|
1070
|
-
[
|
|
1071
|
-
"-1",
|
|
1072
|
-
"true",
|
|
1073
|
-
"f1",
|
|
1074
|
-
"f2",
|
|
1075
|
-
"-2",
|
|
1076
|
-
"false",
|
|
1077
|
-
],
|
|
892
|
+
["-1", "true", "f1", "f2", "-2", "false"],
|
|
1078
893
|
undefined,
|
|
1079
894
|
);
|
|
1080
|
-
expectExtractResult(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
895
|
+
expectExtractResult(
|
|
896
|
+
result,
|
|
897
|
+
{
|
|
898
|
+
goo1: "true",
|
|
899
|
+
goo2: "false",
|
|
900
|
+
foo1: "f1",
|
|
901
|
+
foo2: "f2",
|
|
902
|
+
},
|
|
903
|
+
[],
|
|
904
|
+
);
|
|
1086
905
|
expect(result.invalidArgument).toBeUndefined();
|
|
1087
906
|
});
|
|
1088
907
|
|
|
1089
908
|
test("Option array either side of positional", () => {
|
|
1090
909
|
let command: SubCommand = {
|
|
1091
910
|
name: "command",
|
|
1092
|
-
options: [
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
911
|
+
options: [
|
|
912
|
+
{
|
|
913
|
+
name: "foo",
|
|
914
|
+
isArray: true,
|
|
915
|
+
type: ArgumentValueTypeName.STRING,
|
|
916
|
+
},
|
|
917
|
+
],
|
|
918
|
+
positionals: [
|
|
919
|
+
{
|
|
920
|
+
name: "goo",
|
|
921
|
+
type: ArgumentValueTypeName.STRING,
|
|
922
|
+
},
|
|
923
|
+
],
|
|
924
|
+
execute: async (): Promise<void> => {},
|
|
1103
925
|
};
|
|
1104
926
|
|
|
1105
927
|
let result = populateSubCommandValues(
|
|
1106
928
|
command,
|
|
1107
|
-
[
|
|
1108
|
-
"--foo",
|
|
1109
|
-
"f1",
|
|
1110
|
-
"goo1",
|
|
1111
|
-
"--foo",
|
|
1112
|
-
"f2",
|
|
1113
|
-
],
|
|
929
|
+
["--foo", "f1", "goo1", "--foo", "f2"],
|
|
1114
930
|
undefined,
|
|
1115
931
|
);
|
|
1116
|
-
expectExtractResult(
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
932
|
+
expectExtractResult(
|
|
933
|
+
result,
|
|
934
|
+
{
|
|
935
|
+
foo: ["f1", "f2"],
|
|
936
|
+
goo: "goo1",
|
|
937
|
+
},
|
|
938
|
+
[],
|
|
939
|
+
);
|
|
1120
940
|
expect(result.invalidArgument).toBeUndefined();
|
|
1121
941
|
|
|
1122
942
|
command = {
|
|
1123
943
|
name: "command",
|
|
1124
|
-
options: [
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
944
|
+
options: [
|
|
945
|
+
{
|
|
946
|
+
name: "foo",
|
|
947
|
+
isArray: true,
|
|
948
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
949
|
+
},
|
|
950
|
+
],
|
|
951
|
+
positionals: [
|
|
952
|
+
{
|
|
953
|
+
name: "goo",
|
|
954
|
+
type: ArgumentValueTypeName.STRING,
|
|
955
|
+
},
|
|
956
|
+
],
|
|
957
|
+
execute: async (): Promise<void> => {},
|
|
1135
958
|
};
|
|
1136
959
|
result = populateSubCommandValues(
|
|
1137
960
|
command,
|
|
1138
|
-
[
|
|
1139
|
-
"--foo",
|
|
1140
|
-
"true",
|
|
1141
|
-
"goo1",
|
|
1142
|
-
"--foo",
|
|
1143
|
-
"false",
|
|
1144
|
-
],
|
|
961
|
+
["--foo", "true", "goo1", "--foo", "false"],
|
|
1145
962
|
undefined,
|
|
1146
963
|
);
|
|
1147
|
-
expectExtractResult(
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
964
|
+
expectExtractResult(
|
|
965
|
+
result,
|
|
966
|
+
{
|
|
967
|
+
foo: ["true", "false"],
|
|
968
|
+
goo: "goo1",
|
|
969
|
+
},
|
|
970
|
+
[],
|
|
971
|
+
);
|
|
1151
972
|
expect(result.invalidArgument).toBeUndefined();
|
|
1152
973
|
|
|
1153
|
-
result = populateSubCommandValues(
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
974
|
+
result = populateSubCommandValues(command, ["--foo", "goo1", "--foo"], undefined);
|
|
975
|
+
expectExtractResult(
|
|
976
|
+
result,
|
|
977
|
+
{
|
|
978
|
+
foo: ["true", "true"],
|
|
979
|
+
goo: "goo1",
|
|
980
|
+
},
|
|
981
|
+
[],
|
|
1157
982
|
);
|
|
1158
|
-
expectExtractResult(result, {
|
|
1159
|
-
foo: ["true", "true"],
|
|
1160
|
-
goo: "goo1",
|
|
1161
|
-
}, []);
|
|
1162
983
|
expect(result.invalidArgument).toBeUndefined();
|
|
1163
984
|
});
|
|
1164
985
|
|
|
1165
986
|
test("Unused option after used option", () => {
|
|
1166
987
|
let command: SubCommand = {
|
|
1167
988
|
name: "command",
|
|
1168
|
-
options: [
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
989
|
+
options: [
|
|
990
|
+
{
|
|
991
|
+
name: "foo",
|
|
992
|
+
shortAlias: "f",
|
|
993
|
+
type: ArgumentValueTypeName.STRING,
|
|
994
|
+
},
|
|
995
|
+
],
|
|
1173
996
|
positionals: [],
|
|
1174
|
-
execute: async (): Promise<void> => {
|
|
1175
|
-
},
|
|
997
|
+
execute: async (): Promise<void> => {},
|
|
1176
998
|
};
|
|
1177
999
|
|
|
1178
|
-
let result = populateSubCommandValues(
|
|
1179
|
-
command,
|
|
1180
|
-
[
|
|
1181
|
-
"--foo",
|
|
1182
|
-
"bar",
|
|
1183
|
-
"--goo",
|
|
1184
|
-
"gar",
|
|
1185
|
-
],
|
|
1186
|
-
undefined,
|
|
1187
|
-
);
|
|
1000
|
+
let result = populateSubCommandValues(command, ["--foo", "bar", "--goo", "gar"], undefined);
|
|
1188
1001
|
expectExtractResult(result, { foo: "bar" }, ["--goo", "gar"]);
|
|
1189
1002
|
expect(result.invalidArgument).toBeUndefined();
|
|
1190
1003
|
|
|
1191
|
-
result = populateSubCommandValues(
|
|
1192
|
-
command,
|
|
1193
|
-
["--foo=bar", "--goo=gar"],
|
|
1194
|
-
undefined,
|
|
1195
|
-
);
|
|
1004
|
+
result = populateSubCommandValues(command, ["--foo=bar", "--goo=gar"], undefined);
|
|
1196
1005
|
expectExtractResult(result, { foo: "bar" }, ["--goo=gar"]);
|
|
1197
1006
|
expect(result.invalidArgument).toBeUndefined();
|
|
1198
1007
|
|
|
1199
1008
|
command = {
|
|
1200
1009
|
name: "command",
|
|
1201
|
-
options: [
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1010
|
+
options: [
|
|
1011
|
+
{
|
|
1012
|
+
name: "foo",
|
|
1013
|
+
shortAlias: "f",
|
|
1014
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1015
|
+
},
|
|
1016
|
+
],
|
|
1206
1017
|
positionals: [],
|
|
1207
|
-
execute: async (): Promise<void> => {
|
|
1208
|
-
},
|
|
1018
|
+
execute: async (): Promise<void> => {},
|
|
1209
1019
|
};
|
|
1210
1020
|
|
|
1211
|
-
result = populateSubCommandValues(
|
|
1212
|
-
command,
|
|
1213
|
-
["-f", "--goo", "gar"],
|
|
1214
|
-
undefined,
|
|
1215
|
-
);
|
|
1021
|
+
result = populateSubCommandValues(command, ["-f", "--goo", "gar"], undefined);
|
|
1216
1022
|
expectExtractResult(result, { foo: "true" }, ["--goo", "gar"]);
|
|
1217
1023
|
expect(result.invalidArgument).toBeUndefined();
|
|
1218
1024
|
});
|
|
@@ -1220,54 +1026,39 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1220
1026
|
test("Unused option before used option", () => {
|
|
1221
1027
|
let command: SubCommand = {
|
|
1222
1028
|
name: "command",
|
|
1223
|
-
options: [
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1029
|
+
options: [
|
|
1030
|
+
{
|
|
1031
|
+
name: "foo",
|
|
1032
|
+
shortAlias: "f",
|
|
1033
|
+
type: ArgumentValueTypeName.STRING,
|
|
1034
|
+
},
|
|
1035
|
+
],
|
|
1228
1036
|
positionals: [],
|
|
1229
|
-
execute: async (): Promise<void> => {
|
|
1230
|
-
},
|
|
1037
|
+
execute: async (): Promise<void> => {},
|
|
1231
1038
|
};
|
|
1232
1039
|
|
|
1233
|
-
let result = populateSubCommandValues(
|
|
1234
|
-
command,
|
|
1235
|
-
[
|
|
1236
|
-
"--goo",
|
|
1237
|
-
"gar",
|
|
1238
|
-
"--foo",
|
|
1239
|
-
"bar",
|
|
1240
|
-
],
|
|
1241
|
-
undefined,
|
|
1242
|
-
);
|
|
1040
|
+
let result = populateSubCommandValues(command, ["--goo", "gar", "--foo", "bar"], undefined);
|
|
1243
1041
|
expectExtractResult(result, { foo: "bar" }, ["--goo", "gar"]);
|
|
1244
1042
|
expect(result.invalidArgument).toBeUndefined();
|
|
1245
1043
|
|
|
1246
|
-
result = populateSubCommandValues(
|
|
1247
|
-
command,
|
|
1248
|
-
["--goo=gar", "--foo=bar"],
|
|
1249
|
-
undefined,
|
|
1250
|
-
);
|
|
1044
|
+
result = populateSubCommandValues(command, ["--goo=gar", "--foo=bar"], undefined);
|
|
1251
1045
|
expectExtractResult(result, { foo: "bar" }, ["--goo=gar"]);
|
|
1252
1046
|
expect(result.invalidArgument).toBeUndefined();
|
|
1253
1047
|
|
|
1254
1048
|
command = {
|
|
1255
1049
|
name: "command",
|
|
1256
|
-
options: [
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1050
|
+
options: [
|
|
1051
|
+
{
|
|
1052
|
+
name: "foo",
|
|
1053
|
+
shortAlias: "f",
|
|
1054
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1055
|
+
},
|
|
1056
|
+
],
|
|
1261
1057
|
positionals: [],
|
|
1262
|
-
execute: async (): Promise<void> => {
|
|
1263
|
-
},
|
|
1058
|
+
execute: async (): Promise<void> => {},
|
|
1264
1059
|
};
|
|
1265
1060
|
|
|
1266
|
-
result = populateSubCommandValues(
|
|
1267
|
-
command,
|
|
1268
|
-
["--goo", "gar", "-f"],
|
|
1269
|
-
undefined,
|
|
1270
|
-
);
|
|
1061
|
+
result = populateSubCommandValues(command, ["--goo", "gar", "-f"], undefined);
|
|
1271
1062
|
expectExtractResult(result, { foo: "true" }, ["--goo", "gar"]);
|
|
1272
1063
|
expect(result.invalidArgument).toBeUndefined();
|
|
1273
1064
|
});
|
|
@@ -1275,51 +1066,48 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1275
1066
|
test("Unused option after positional", () => {
|
|
1276
1067
|
const command: SubCommand = {
|
|
1277
1068
|
name: "command",
|
|
1278
|
-
options: [
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1069
|
+
options: [
|
|
1070
|
+
{
|
|
1071
|
+
name: "foo1",
|
|
1072
|
+
shortAlias: "1",
|
|
1073
|
+
type: ArgumentValueTypeName.STRING,
|
|
1074
|
+
},
|
|
1075
|
+
],
|
|
1076
|
+
positionals: [
|
|
1077
|
+
{
|
|
1078
|
+
name: "foo2",
|
|
1079
|
+
type: ArgumentValueTypeName.STRING,
|
|
1080
|
+
},
|
|
1081
|
+
],
|
|
1082
|
+
execute: async (): Promise<void> => {},
|
|
1289
1083
|
};
|
|
1290
1084
|
|
|
1291
1085
|
const result = populateSubCommandValues(
|
|
1292
1086
|
command,
|
|
1293
|
-
[
|
|
1294
|
-
"--foo1",
|
|
1295
|
-
"bar",
|
|
1296
|
-
"foo2",
|
|
1297
|
-
"--goo",
|
|
1298
|
-
"gar",
|
|
1299
|
-
],
|
|
1087
|
+
["--foo1", "bar", "foo2", "--goo", "gar"],
|
|
1300
1088
|
undefined,
|
|
1301
1089
|
);
|
|
1302
|
-
expectExtractResult(result, { foo1: "bar", foo2: "foo2" }, [
|
|
1303
|
-
"--goo",
|
|
1304
|
-
"gar",
|
|
1305
|
-
]);
|
|
1090
|
+
expectExtractResult(result, { foo1: "bar", foo2: "foo2" }, ["--goo", "gar"]);
|
|
1306
1091
|
expect(result.invalidArgument).toBeUndefined();
|
|
1307
1092
|
});
|
|
1308
1093
|
|
|
1309
1094
|
test("Unused option before positional", () => {
|
|
1310
1095
|
const command: SubCommand = {
|
|
1311
1096
|
name: "command",
|
|
1312
|
-
options: [
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1097
|
+
options: [
|
|
1098
|
+
{
|
|
1099
|
+
name: "foo1",
|
|
1100
|
+
shortAlias: "1",
|
|
1101
|
+
type: ArgumentValueTypeName.STRING,
|
|
1102
|
+
},
|
|
1103
|
+
],
|
|
1104
|
+
positionals: [
|
|
1105
|
+
{
|
|
1106
|
+
name: "foo2",
|
|
1107
|
+
type: ArgumentValueTypeName.STRING,
|
|
1108
|
+
},
|
|
1109
|
+
],
|
|
1110
|
+
execute: async (): Promise<void> => {},
|
|
1323
1111
|
};
|
|
1324
1112
|
|
|
1325
1113
|
const result = populateSubCommandValues(
|
|
@@ -1333,10 +1121,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1333
1121
|
],
|
|
1334
1122
|
undefined,
|
|
1335
1123
|
);
|
|
1336
|
-
expectExtractResult(result, { foo1: "bar", foo2: "--goo" }, [
|
|
1337
|
-
"gar",
|
|
1338
|
-
"foo2",
|
|
1339
|
-
]);
|
|
1124
|
+
expectExtractResult(result, { foo1: "bar", foo2: "--goo" }, ["gar", "foo2"]);
|
|
1340
1125
|
expect(result.invalidArgument).toBeUndefined();
|
|
1341
1126
|
});
|
|
1342
1127
|
|
|
@@ -1344,19 +1129,16 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1344
1129
|
const command: SubCommand = {
|
|
1345
1130
|
name: "command",
|
|
1346
1131
|
options: [],
|
|
1347
|
-
positionals: [
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1132
|
+
positionals: [
|
|
1133
|
+
{
|
|
1134
|
+
name: "foo",
|
|
1135
|
+
type: ArgumentValueTypeName.STRING,
|
|
1136
|
+
},
|
|
1137
|
+
],
|
|
1138
|
+
execute: async (): Promise<void> => {},
|
|
1353
1139
|
};
|
|
1354
1140
|
|
|
1355
|
-
const result = populateSubCommandValues(
|
|
1356
|
-
command,
|
|
1357
|
-
["bar", "goo"],
|
|
1358
|
-
undefined,
|
|
1359
|
-
);
|
|
1141
|
+
const result = populateSubCommandValues(command, ["bar", "goo"], undefined);
|
|
1360
1142
|
expectExtractResult(result, { foo: "bar" }, ["goo"]);
|
|
1361
1143
|
expect(result.invalidArgument).toBeUndefined();
|
|
1362
1144
|
});
|
|
@@ -1364,39 +1146,33 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1364
1146
|
test("Unused positional after optional", () => {
|
|
1365
1147
|
let command: SubCommand = {
|
|
1366
1148
|
name: "command",
|
|
1367
|
-
options: [
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1149
|
+
options: [
|
|
1150
|
+
{
|
|
1151
|
+
name: "foo",
|
|
1152
|
+
type: ArgumentValueTypeName.STRING,
|
|
1153
|
+
},
|
|
1154
|
+
],
|
|
1371
1155
|
positionals: [],
|
|
1372
|
-
execute: async (): Promise<void> => {
|
|
1373
|
-
},
|
|
1156
|
+
execute: async (): Promise<void> => {},
|
|
1374
1157
|
};
|
|
1375
1158
|
|
|
1376
|
-
let result = populateSubCommandValues(
|
|
1377
|
-
command,
|
|
1378
|
-
["--foo", "bar", "goo"],
|
|
1379
|
-
undefined,
|
|
1380
|
-
);
|
|
1159
|
+
let result = populateSubCommandValues(command, ["--foo", "bar", "goo"], undefined);
|
|
1381
1160
|
expectExtractResult(result, { foo: "bar" }, ["goo"]);
|
|
1382
1161
|
expect(result.invalidArgument).toBeUndefined();
|
|
1383
1162
|
|
|
1384
1163
|
command = {
|
|
1385
1164
|
name: "command",
|
|
1386
|
-
options: [
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1165
|
+
options: [
|
|
1166
|
+
{
|
|
1167
|
+
name: "foo",
|
|
1168
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1169
|
+
},
|
|
1170
|
+
],
|
|
1390
1171
|
positionals: [],
|
|
1391
|
-
execute: async (): Promise<void> => {
|
|
1392
|
-
},
|
|
1172
|
+
execute: async (): Promise<void> => {},
|
|
1393
1173
|
};
|
|
1394
1174
|
|
|
1395
|
-
result = populateSubCommandValues(
|
|
1396
|
-
command,
|
|
1397
|
-
["--foo", "goo"],
|
|
1398
|
-
undefined,
|
|
1399
|
-
);
|
|
1175
|
+
result = populateSubCommandValues(command, ["--foo", "goo"], undefined);
|
|
1400
1176
|
expectExtractResult(result, { foo: "true" }, ["goo"]);
|
|
1401
1177
|
expect(result.invalidArgument).toBeUndefined();
|
|
1402
1178
|
});
|
|
@@ -1404,281 +1180,283 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1404
1180
|
test("Positionals either side of options", () => {
|
|
1405
1181
|
let command: SubCommand = {
|
|
1406
1182
|
name: "command",
|
|
1407
|
-
options: [
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1183
|
+
options: [
|
|
1184
|
+
{
|
|
1185
|
+
name: "goo1",
|
|
1186
|
+
type: ArgumentValueTypeName.STRING,
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
name: "goo2",
|
|
1190
|
+
type: ArgumentValueTypeName.STRING,
|
|
1191
|
+
},
|
|
1192
|
+
],
|
|
1193
|
+
positionals: [
|
|
1194
|
+
{
|
|
1195
|
+
name: "foo1",
|
|
1196
|
+
type: ArgumentValueTypeName.STRING,
|
|
1197
|
+
},
|
|
1198
|
+
{
|
|
1199
|
+
name: "foo2",
|
|
1200
|
+
type: ArgumentValueTypeName.STRING,
|
|
1201
|
+
},
|
|
1202
|
+
],
|
|
1203
|
+
execute: async (): Promise<void> => {},
|
|
1423
1204
|
};
|
|
1424
1205
|
|
|
1425
1206
|
let result = populateSubCommandValues(
|
|
1426
1207
|
command,
|
|
1427
|
-
[
|
|
1428
|
-
"f1",
|
|
1429
|
-
"--goo1",
|
|
1430
|
-
"g1",
|
|
1431
|
-
"--goo2",
|
|
1432
|
-
"g2",
|
|
1433
|
-
"f2",
|
|
1434
|
-
],
|
|
1208
|
+
["f1", "--goo1", "g1", "--goo2", "g2", "f2"],
|
|
1435
1209
|
undefined,
|
|
1436
1210
|
);
|
|
1437
|
-
expectExtractResult(
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1211
|
+
expectExtractResult(
|
|
1212
|
+
result,
|
|
1213
|
+
{
|
|
1214
|
+
goo1: "g1",
|
|
1215
|
+
goo2: "g2",
|
|
1216
|
+
foo1: "f1",
|
|
1217
|
+
foo2: "f2",
|
|
1218
|
+
},
|
|
1219
|
+
[],
|
|
1220
|
+
);
|
|
1443
1221
|
expect(result.invalidArgument).toBeUndefined();
|
|
1444
1222
|
|
|
1445
1223
|
command = {
|
|
1446
1224
|
name: "command",
|
|
1447
|
-
options: [
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1225
|
+
options: [
|
|
1226
|
+
{
|
|
1227
|
+
name: "goo1",
|
|
1228
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
name: "goo2",
|
|
1232
|
+
type: ArgumentValueTypeName.STRING,
|
|
1233
|
+
},
|
|
1234
|
+
],
|
|
1235
|
+
positionals: [
|
|
1236
|
+
{
|
|
1237
|
+
name: "foo1",
|
|
1238
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
name: "foo2",
|
|
1242
|
+
type: ArgumentValueTypeName.STRING,
|
|
1243
|
+
},
|
|
1244
|
+
],
|
|
1245
|
+
execute: async (): Promise<void> => {},
|
|
1463
1246
|
};
|
|
1464
1247
|
|
|
1465
|
-
result = populateSubCommandValues(
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
"
|
|
1472
|
-
"f2",
|
|
1473
|
-
|
|
1474
|
-
|
|
1248
|
+
result = populateSubCommandValues(command, ["true", "--goo1", "--goo2", "g2", "f2"], undefined);
|
|
1249
|
+
expectExtractResult(
|
|
1250
|
+
result,
|
|
1251
|
+
{
|
|
1252
|
+
goo1: "true",
|
|
1253
|
+
goo2: "g2",
|
|
1254
|
+
foo1: "true",
|
|
1255
|
+
foo2: "f2",
|
|
1256
|
+
},
|
|
1257
|
+
[],
|
|
1475
1258
|
);
|
|
1476
|
-
expectExtractResult(result, {
|
|
1477
|
-
goo1: "true",
|
|
1478
|
-
goo2: "g2",
|
|
1479
|
-
foo1: "true",
|
|
1480
|
-
foo2: "f2",
|
|
1481
|
-
}, []);
|
|
1482
1259
|
expect(result.invalidArgument).toBeUndefined();
|
|
1483
1260
|
});
|
|
1484
1261
|
|
|
1485
1262
|
test("Positionals and non-boolean options interleaved", () => {
|
|
1486
1263
|
const command: SubCommand = {
|
|
1487
1264
|
name: "command",
|
|
1488
|
-
options: [
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1265
|
+
options: [
|
|
1266
|
+
{
|
|
1267
|
+
name: "goo1",
|
|
1268
|
+
type: ArgumentValueTypeName.STRING,
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
name: "goo2",
|
|
1272
|
+
type: ArgumentValueTypeName.STRING,
|
|
1273
|
+
},
|
|
1274
|
+
],
|
|
1275
|
+
positionals: [
|
|
1276
|
+
{
|
|
1277
|
+
name: "foo1",
|
|
1278
|
+
type: ArgumentValueTypeName.STRING,
|
|
1279
|
+
},
|
|
1280
|
+
{
|
|
1281
|
+
name: "foo2",
|
|
1282
|
+
type: ArgumentValueTypeName.STRING,
|
|
1283
|
+
},
|
|
1284
|
+
],
|
|
1285
|
+
execute: async (): Promise<void> => {},
|
|
1504
1286
|
};
|
|
1505
1287
|
|
|
1506
1288
|
let result = populateSubCommandValues(
|
|
1507
1289
|
command,
|
|
1508
|
-
[
|
|
1509
|
-
"f1",
|
|
1510
|
-
"--goo1",
|
|
1511
|
-
"g1",
|
|
1512
|
-
"f2",
|
|
1513
|
-
"--goo2",
|
|
1514
|
-
"g2",
|
|
1515
|
-
],
|
|
1290
|
+
["f1", "--goo1", "g1", "f2", "--goo2", "g2"],
|
|
1516
1291
|
undefined,
|
|
1517
1292
|
);
|
|
1518
|
-
expectExtractResult(
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1293
|
+
expectExtractResult(
|
|
1294
|
+
result,
|
|
1295
|
+
{
|
|
1296
|
+
goo1: "g1",
|
|
1297
|
+
goo2: "g2",
|
|
1298
|
+
foo1: "f1",
|
|
1299
|
+
foo2: "f2",
|
|
1300
|
+
},
|
|
1301
|
+
[],
|
|
1302
|
+
);
|
|
1524
1303
|
expect(result.invalidArgument).toBeUndefined();
|
|
1525
1304
|
|
|
1526
1305
|
result = populateSubCommandValues(
|
|
1527
1306
|
command,
|
|
1528
|
-
[
|
|
1529
|
-
"--goo1",
|
|
1530
|
-
"g1",
|
|
1531
|
-
"f1",
|
|
1532
|
-
"--goo2",
|
|
1533
|
-
"g2",
|
|
1534
|
-
"f2",
|
|
1535
|
-
],
|
|
1307
|
+
["--goo1", "g1", "f1", "--goo2", "g2", "f2"],
|
|
1536
1308
|
undefined,
|
|
1537
1309
|
);
|
|
1538
|
-
expectExtractResult(
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1310
|
+
expectExtractResult(
|
|
1311
|
+
result,
|
|
1312
|
+
{
|
|
1313
|
+
goo1: "g1",
|
|
1314
|
+
goo2: "g2",
|
|
1315
|
+
foo1: "f1",
|
|
1316
|
+
foo2: "f2",
|
|
1317
|
+
},
|
|
1318
|
+
[],
|
|
1319
|
+
);
|
|
1544
1320
|
expect(result.invalidArgument).toBeUndefined();
|
|
1545
1321
|
});
|
|
1546
1322
|
|
|
1547
1323
|
test("Positionals and boolean options interleaved", () => {
|
|
1548
1324
|
const command: SubCommand = {
|
|
1549
1325
|
name: "command",
|
|
1550
|
-
options: [
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1326
|
+
options: [
|
|
1327
|
+
{
|
|
1328
|
+
name: "goo1",
|
|
1329
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1330
|
+
},
|
|
1331
|
+
{
|
|
1332
|
+
name: "goo2",
|
|
1333
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1334
|
+
},
|
|
1335
|
+
],
|
|
1336
|
+
positionals: [
|
|
1337
|
+
{
|
|
1338
|
+
name: "foo1",
|
|
1339
|
+
type: ArgumentValueTypeName.STRING,
|
|
1340
|
+
},
|
|
1341
|
+
{
|
|
1342
|
+
name: "foo2",
|
|
1343
|
+
type: ArgumentValueTypeName.STRING,
|
|
1344
|
+
},
|
|
1345
|
+
],
|
|
1346
|
+
execute: async (): Promise<void> => {},
|
|
1566
1347
|
};
|
|
1567
1348
|
|
|
1568
1349
|
let result = populateSubCommandValues(
|
|
1569
1350
|
command,
|
|
1570
|
-
[
|
|
1571
|
-
"f1",
|
|
1572
|
-
"--goo1",
|
|
1573
|
-
"true",
|
|
1574
|
-
"f2",
|
|
1575
|
-
"--goo2",
|
|
1576
|
-
"true",
|
|
1577
|
-
],
|
|
1351
|
+
["f1", "--goo1", "true", "f2", "--goo2", "true"],
|
|
1578
1352
|
undefined,
|
|
1579
1353
|
);
|
|
1580
|
-
expectExtractResult(
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1354
|
+
expectExtractResult(
|
|
1355
|
+
result,
|
|
1356
|
+
{
|
|
1357
|
+
goo1: "true",
|
|
1358
|
+
goo2: "true",
|
|
1359
|
+
foo1: "f1",
|
|
1360
|
+
foo2: "f2",
|
|
1361
|
+
},
|
|
1362
|
+
[],
|
|
1363
|
+
);
|
|
1586
1364
|
expect(result.invalidArgument).toBeUndefined();
|
|
1587
1365
|
|
|
1588
|
-
result = populateSubCommandValues(
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1366
|
+
result = populateSubCommandValues(command, ["f1", "--goo1", "f2", "--goo2"], undefined);
|
|
1367
|
+
expectExtractResult(
|
|
1368
|
+
result,
|
|
1369
|
+
{
|
|
1370
|
+
goo1: "true",
|
|
1371
|
+
goo2: "true",
|
|
1372
|
+
foo1: "f1",
|
|
1373
|
+
foo2: "f2",
|
|
1374
|
+
},
|
|
1375
|
+
[],
|
|
1592
1376
|
);
|
|
1593
|
-
expectExtractResult(result, {
|
|
1594
|
-
goo1: "true",
|
|
1595
|
-
goo2: "true",
|
|
1596
|
-
foo1: "f1",
|
|
1597
|
-
foo2: "f2",
|
|
1598
|
-
}, []);
|
|
1599
1377
|
expect(result.invalidArgument).toBeUndefined();
|
|
1600
1378
|
});
|
|
1601
1379
|
|
|
1602
1380
|
test("Array option before vararg positional", () => {
|
|
1603
1381
|
const command: SubCommand = {
|
|
1604
1382
|
name: "command",
|
|
1605
|
-
options: [
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1383
|
+
options: [
|
|
1384
|
+
{
|
|
1385
|
+
name: "foo",
|
|
1386
|
+
type: ArgumentValueTypeName.STRING,
|
|
1387
|
+
isArray: true,
|
|
1388
|
+
},
|
|
1389
|
+
],
|
|
1390
|
+
positionals: [
|
|
1391
|
+
{
|
|
1392
|
+
name: "goo",
|
|
1393
|
+
type: ArgumentValueTypeName.STRING,
|
|
1394
|
+
isVarargMultiple: true,
|
|
1395
|
+
},
|
|
1396
|
+
],
|
|
1397
|
+
execute: async (): Promise<void> => {},
|
|
1617
1398
|
};
|
|
1618
1399
|
|
|
1619
1400
|
const result = populateSubCommandValues(
|
|
1620
1401
|
command,
|
|
1621
|
-
[
|
|
1622
|
-
"--foo",
|
|
1623
|
-
"f1",
|
|
1624
|
-
"--foo",
|
|
1625
|
-
"f2",
|
|
1626
|
-
"g1",
|
|
1627
|
-
"g2",
|
|
1628
|
-
],
|
|
1402
|
+
["--foo", "f1", "--foo", "f2", "g1", "g2"],
|
|
1629
1403
|
undefined,
|
|
1630
1404
|
);
|
|
1631
|
-
expectExtractResult(
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1405
|
+
expectExtractResult(
|
|
1406
|
+
result,
|
|
1407
|
+
{
|
|
1408
|
+
foo: ["f1", "f2"],
|
|
1409
|
+
goo: ["g1", "g2"],
|
|
1410
|
+
},
|
|
1411
|
+
[],
|
|
1412
|
+
);
|
|
1635
1413
|
expect(result.invalidArgument).toBeUndefined();
|
|
1636
1414
|
});
|
|
1637
1415
|
|
|
1638
1416
|
test("Vararg positional before array option", () => {
|
|
1639
1417
|
const command: SubCommand = {
|
|
1640
1418
|
name: "command",
|
|
1641
|
-
options: [
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1419
|
+
options: [
|
|
1420
|
+
{
|
|
1421
|
+
name: "foo",
|
|
1422
|
+
type: ArgumentValueTypeName.STRING,
|
|
1423
|
+
isArray: true,
|
|
1424
|
+
},
|
|
1425
|
+
],
|
|
1426
|
+
positionals: [
|
|
1427
|
+
{
|
|
1428
|
+
name: "goo",
|
|
1429
|
+
type: ArgumentValueTypeName.STRING,
|
|
1430
|
+
isVarargMultiple: true,
|
|
1431
|
+
isVarargOptional: true,
|
|
1432
|
+
},
|
|
1433
|
+
],
|
|
1434
|
+
execute: async (): Promise<void> => {},
|
|
1654
1435
|
};
|
|
1655
1436
|
|
|
1656
1437
|
let result = populateSubCommandValues(
|
|
1657
1438
|
command,
|
|
1658
|
-
[
|
|
1659
|
-
"g1",
|
|
1660
|
-
"g2",
|
|
1661
|
-
"--foo",
|
|
1662
|
-
"f1",
|
|
1663
|
-
"--foo",
|
|
1664
|
-
"f2",
|
|
1665
|
-
],
|
|
1439
|
+
["g1", "g2", "--foo", "f1", "--foo", "f2"],
|
|
1666
1440
|
undefined,
|
|
1667
1441
|
);
|
|
1668
|
-
expectExtractResult(
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1442
|
+
expectExtractResult(
|
|
1443
|
+
result,
|
|
1444
|
+
{
|
|
1445
|
+
foo: ["f1", "f2"],
|
|
1446
|
+
goo: ["g1", "g2"],
|
|
1447
|
+
},
|
|
1448
|
+
[],
|
|
1449
|
+
);
|
|
1672
1450
|
expect(result.invalidArgument).toBeUndefined();
|
|
1673
1451
|
|
|
1674
|
-
result = populateSubCommandValues(
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1452
|
+
result = populateSubCommandValues(command, ["--foo", "f1", "--foo", "f2"], undefined);
|
|
1453
|
+
expectExtractResult(
|
|
1454
|
+
result,
|
|
1455
|
+
{
|
|
1456
|
+
foo: ["f1", "f2"],
|
|
1457
|
+
},
|
|
1458
|
+
[],
|
|
1678
1459
|
);
|
|
1679
|
-
expectExtractResult(result, {
|
|
1680
|
-
foo: ["f1", "f2"],
|
|
1681
|
-
}, []);
|
|
1682
1460
|
expect(result.invalidArgument).toBeUndefined();
|
|
1683
1461
|
});
|
|
1684
1462
|
|
|
@@ -1686,55 +1464,46 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1686
1464
|
let command: SubCommand = {
|
|
1687
1465
|
name: "command",
|
|
1688
1466
|
options: [],
|
|
1689
|
-
positionals: [
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1467
|
+
positionals: [
|
|
1468
|
+
{
|
|
1469
|
+
name: "foo",
|
|
1470
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
1471
|
+
},
|
|
1472
|
+
],
|
|
1473
|
+
execute: async (): Promise<void> => {},
|
|
1695
1474
|
};
|
|
1696
1475
|
|
|
1697
|
-
let result = populateSubCommandValues(
|
|
1698
|
-
command,
|
|
1699
|
-
["1"],
|
|
1700
|
-
{ foo: 2 },
|
|
1701
|
-
);
|
|
1476
|
+
let result = populateSubCommandValues(command, ["1"], { foo: 2 });
|
|
1702
1477
|
expectExtractResult(result, { foo: "1" }, []);
|
|
1703
1478
|
expect(result.invalidArgument).toBeUndefined();
|
|
1704
1479
|
|
|
1705
1480
|
command = {
|
|
1706
1481
|
name: "command",
|
|
1707
1482
|
options: [],
|
|
1708
|
-
positionals: [
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1483
|
+
positionals: [
|
|
1484
|
+
{
|
|
1485
|
+
name: "foo",
|
|
1486
|
+
type: ArgumentValueTypeName.STRING,
|
|
1487
|
+
},
|
|
1488
|
+
],
|
|
1489
|
+
execute: async (): Promise<void> => {},
|
|
1714
1490
|
};
|
|
1715
|
-
result = populateSubCommandValues(
|
|
1716
|
-
command,
|
|
1717
|
-
["bar"],
|
|
1718
|
-
{ foo: "nope" },
|
|
1719
|
-
);
|
|
1491
|
+
result = populateSubCommandValues(command, ["bar"], { foo: "nope" });
|
|
1720
1492
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
1721
1493
|
expect(result.invalidArgument).toBeUndefined();
|
|
1722
1494
|
|
|
1723
1495
|
command = {
|
|
1724
1496
|
name: "command",
|
|
1725
1497
|
options: [],
|
|
1726
|
-
positionals: [
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
["true"],
|
|
1736
|
-
{ foo: false },
|
|
1737
|
-
);
|
|
1498
|
+
positionals: [
|
|
1499
|
+
{
|
|
1500
|
+
name: "foo",
|
|
1501
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1502
|
+
},
|
|
1503
|
+
],
|
|
1504
|
+
execute: async (): Promise<void> => {},
|
|
1505
|
+
};
|
|
1506
|
+
result = populateSubCommandValues(command, ["true"], { foo: false });
|
|
1738
1507
|
expectExtractResult(result, { foo: "true" }, []);
|
|
1739
1508
|
expect(result.invalidArgument).toBeUndefined();
|
|
1740
1509
|
});
|
|
@@ -1743,58 +1512,49 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1743
1512
|
let command: SubCommand = {
|
|
1744
1513
|
name: "command",
|
|
1745
1514
|
options: [],
|
|
1746
|
-
positionals: [
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1515
|
+
positionals: [
|
|
1516
|
+
{
|
|
1517
|
+
name: "foo",
|
|
1518
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
1519
|
+
isVarargOptional: true,
|
|
1520
|
+
},
|
|
1521
|
+
],
|
|
1522
|
+
execute: async (): Promise<void> => {},
|
|
1753
1523
|
};
|
|
1754
1524
|
|
|
1755
|
-
let result = populateSubCommandValues(
|
|
1756
|
-
command,
|
|
1757
|
-
[],
|
|
1758
|
-
{ foo: 1 },
|
|
1759
|
-
);
|
|
1525
|
+
let result = populateSubCommandValues(command, [], { foo: 1 });
|
|
1760
1526
|
expectExtractResult(result, { foo: 1 }, []);
|
|
1761
1527
|
expect(result.invalidArgument).toBeUndefined();
|
|
1762
1528
|
|
|
1763
1529
|
command = {
|
|
1764
1530
|
name: "command",
|
|
1765
1531
|
options: [],
|
|
1766
|
-
positionals: [
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1532
|
+
positionals: [
|
|
1533
|
+
{
|
|
1534
|
+
name: "foo",
|
|
1535
|
+
type: ArgumentValueTypeName.STRING,
|
|
1536
|
+
isVarargOptional: true,
|
|
1537
|
+
},
|
|
1538
|
+
],
|
|
1539
|
+
execute: async (): Promise<void> => {},
|
|
1773
1540
|
};
|
|
1774
|
-
result = populateSubCommandValues(
|
|
1775
|
-
command,
|
|
1776
|
-
[],
|
|
1777
|
-
{ foo: "bar" },
|
|
1778
|
-
);
|
|
1541
|
+
result = populateSubCommandValues(command, [], { foo: "bar" });
|
|
1779
1542
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
1780
1543
|
expect(result.invalidArgument).toBeUndefined();
|
|
1781
1544
|
|
|
1782
1545
|
command = {
|
|
1783
1546
|
name: "command",
|
|
1784
1547
|
options: [],
|
|
1785
|
-
positionals: [
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1548
|
+
positionals: [
|
|
1549
|
+
{
|
|
1550
|
+
name: "foo",
|
|
1551
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1552
|
+
isVarargOptional: true,
|
|
1553
|
+
},
|
|
1554
|
+
],
|
|
1555
|
+
execute: async (): Promise<void> => {},
|
|
1792
1556
|
};
|
|
1793
|
-
result = populateSubCommandValues(
|
|
1794
|
-
command,
|
|
1795
|
-
[],
|
|
1796
|
-
{ foo: true },
|
|
1797
|
-
);
|
|
1557
|
+
result = populateSubCommandValues(command, [], { foo: true });
|
|
1798
1558
|
expectExtractResult(result, { foo: true }, []);
|
|
1799
1559
|
expect(result.invalidArgument).toBeUndefined();
|
|
1800
1560
|
});
|
|
@@ -1803,61 +1563,52 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1803
1563
|
let command: SubCommand = {
|
|
1804
1564
|
name: "command",
|
|
1805
1565
|
options: [],
|
|
1806
|
-
positionals: [
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1566
|
+
positionals: [
|
|
1567
|
+
{
|
|
1568
|
+
name: "foo",
|
|
1569
|
+
type: ArgumentValueTypeName.NUMBER,
|
|
1570
|
+
isVarargOptional: false,
|
|
1571
|
+
isVarargMultiple: true,
|
|
1572
|
+
},
|
|
1573
|
+
],
|
|
1574
|
+
execute: async (): Promise<void> => {},
|
|
1814
1575
|
};
|
|
1815
1576
|
|
|
1816
|
-
let result = populateSubCommandValues(
|
|
1817
|
-
command,
|
|
1818
|
-
[],
|
|
1819
|
-
{ foo: 1 },
|
|
1820
|
-
);
|
|
1577
|
+
let result = populateSubCommandValues(command, [], { foo: 1 });
|
|
1821
1578
|
expectExtractResult(result, { foo: 1 }, []);
|
|
1822
1579
|
expect(result.invalidArgument).toBeUndefined();
|
|
1823
1580
|
|
|
1824
1581
|
command = {
|
|
1825
1582
|
name: "command",
|
|
1826
1583
|
options: [],
|
|
1827
|
-
positionals: [
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1584
|
+
positionals: [
|
|
1585
|
+
{
|
|
1586
|
+
name: "foo",
|
|
1587
|
+
type: ArgumentValueTypeName.STRING,
|
|
1588
|
+
isVarargOptional: false,
|
|
1589
|
+
isVarargMultiple: true,
|
|
1590
|
+
},
|
|
1591
|
+
],
|
|
1592
|
+
execute: async (): Promise<void> => {},
|
|
1835
1593
|
};
|
|
1836
|
-
result = populateSubCommandValues(
|
|
1837
|
-
command,
|
|
1838
|
-
[],
|
|
1839
|
-
{ foo: "bar" },
|
|
1840
|
-
);
|
|
1594
|
+
result = populateSubCommandValues(command, [], { foo: "bar" });
|
|
1841
1595
|
expectExtractResult(result, { foo: "bar" }, []);
|
|
1842
1596
|
expect(result.invalidArgument).toBeUndefined();
|
|
1843
1597
|
|
|
1844
1598
|
command = {
|
|
1845
1599
|
name: "command",
|
|
1846
1600
|
options: [],
|
|
1847
|
-
positionals: [
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1601
|
+
positionals: [
|
|
1602
|
+
{
|
|
1603
|
+
name: "foo",
|
|
1604
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1605
|
+
isVarargOptional: false,
|
|
1606
|
+
isVarargMultiple: true,
|
|
1607
|
+
},
|
|
1608
|
+
],
|
|
1609
|
+
execute: async (): Promise<void> => {},
|
|
1855
1610
|
};
|
|
1856
|
-
result = populateSubCommandValues(
|
|
1857
|
-
command,
|
|
1858
|
-
[],
|
|
1859
|
-
{ foo: true },
|
|
1860
|
-
);
|
|
1611
|
+
result = populateSubCommandValues(command, [], { foo: true });
|
|
1861
1612
|
expectExtractResult(result, { foo: true }, []);
|
|
1862
1613
|
expect(result.invalidArgument).toBeUndefined();
|
|
1863
1614
|
});
|
|
@@ -1865,21 +1616,20 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1865
1616
|
test("Option array configured single values completely overridden by multiple args", () => {
|
|
1866
1617
|
const command: SubCommand = {
|
|
1867
1618
|
name: "command",
|
|
1868
|
-
options: [
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1619
|
+
options: [
|
|
1620
|
+
{
|
|
1621
|
+
name: "foo",
|
|
1622
|
+
type: ArgumentValueTypeName.STRING,
|
|
1623
|
+
isArray: true,
|
|
1624
|
+
},
|
|
1625
|
+
],
|
|
1873
1626
|
positionals: [],
|
|
1874
|
-
execute: async (): Promise<void> => {
|
|
1875
|
-
},
|
|
1627
|
+
execute: async (): Promise<void> => {},
|
|
1876
1628
|
};
|
|
1877
1629
|
|
|
1878
|
-
const result = populateSubCommandValues(
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
{ foo: ["bar"] },
|
|
1882
|
-
);
|
|
1630
|
+
const result = populateSubCommandValues(command, ["--foo", "bar1", "--foo", "bar2"], {
|
|
1631
|
+
foo: ["bar"],
|
|
1632
|
+
});
|
|
1883
1633
|
expectExtractResult(result, { foo: ["bar1", "bar2"] }, []);
|
|
1884
1634
|
expect(result.invalidArgument).toBeUndefined();
|
|
1885
1635
|
});
|
|
@@ -1887,21 +1637,20 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1887
1637
|
test("Option array configured multiple values partially overridden by arg", () => {
|
|
1888
1638
|
const command: SubCommand = {
|
|
1889
1639
|
name: "command",
|
|
1890
|
-
options: [
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1640
|
+
options: [
|
|
1641
|
+
{
|
|
1642
|
+
name: "foo",
|
|
1643
|
+
type: ArgumentValueTypeName.STRING,
|
|
1644
|
+
isArray: true,
|
|
1645
|
+
},
|
|
1646
|
+
],
|
|
1895
1647
|
positionals: [],
|
|
1896
|
-
execute: async (): Promise<void> => {
|
|
1897
|
-
},
|
|
1648
|
+
execute: async (): Promise<void> => {},
|
|
1898
1649
|
};
|
|
1899
1650
|
|
|
1900
|
-
const result = populateSubCommandValues(
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
{ foo: ["bar1", "bar2"] },
|
|
1904
|
-
);
|
|
1651
|
+
const result = populateSubCommandValues(command, ["--foo", "bar"], {
|
|
1652
|
+
foo: ["bar1", "bar2"],
|
|
1653
|
+
});
|
|
1905
1654
|
expectExtractResult(result, { foo: ["bar", "bar2"] }, []);
|
|
1906
1655
|
expect(result.invalidArgument).toBeUndefined();
|
|
1907
1656
|
});
|
|
@@ -1910,13 +1659,14 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1910
1659
|
const command: SubCommand = {
|
|
1911
1660
|
name: "command",
|
|
1912
1661
|
options: [],
|
|
1913
|
-
positionals: [
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1662
|
+
positionals: [
|
|
1663
|
+
{
|
|
1664
|
+
name: "foo",
|
|
1665
|
+
type: ArgumentValueTypeName.STRING,
|
|
1666
|
+
isVarargMultiple: true,
|
|
1667
|
+
},
|
|
1668
|
+
],
|
|
1669
|
+
execute: async (): Promise<void> => {},
|
|
1920
1670
|
};
|
|
1921
1671
|
|
|
1922
1672
|
const result = populateSubCommandValues(command, ["bar", "bar"], {
|
|
@@ -1930,13 +1680,14 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1930
1680
|
const command: SubCommand = {
|
|
1931
1681
|
name: "command",
|
|
1932
1682
|
options: [],
|
|
1933
|
-
positionals: [
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1683
|
+
positionals: [
|
|
1684
|
+
{
|
|
1685
|
+
name: "foo",
|
|
1686
|
+
type: ArgumentValueTypeName.STRING,
|
|
1687
|
+
isVarargMultiple: true,
|
|
1688
|
+
},
|
|
1689
|
+
],
|
|
1690
|
+
execute: async (): Promise<void> => {},
|
|
1940
1691
|
};
|
|
1941
1692
|
|
|
1942
1693
|
const result = populateSubCommandValues(command, ["bar"], {
|
|
@@ -1949,46 +1700,31 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1949
1700
|
test("Option array using indices", () => {
|
|
1950
1701
|
const command: SubCommand = {
|
|
1951
1702
|
name: "command",
|
|
1952
|
-
options: [
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1703
|
+
options: [
|
|
1704
|
+
{
|
|
1705
|
+
name: "foo",
|
|
1706
|
+
type: ArgumentValueTypeName.STRING,
|
|
1707
|
+
shortAlias: "f",
|
|
1708
|
+
isArray: true,
|
|
1709
|
+
},
|
|
1710
|
+
],
|
|
1958
1711
|
positionals: [],
|
|
1959
|
-
execute: async (): Promise<void> => {
|
|
1960
|
-
},
|
|
1712
|
+
execute: async (): Promise<void> => {},
|
|
1961
1713
|
};
|
|
1962
1714
|
|
|
1963
|
-
let result = populateSubCommandValues(
|
|
1964
|
-
command,
|
|
1965
|
-
["--foo[0]", "bar"],
|
|
1966
|
-
undefined,
|
|
1967
|
-
);
|
|
1715
|
+
let result = populateSubCommandValues(command, ["--foo[0]", "bar"], undefined);
|
|
1968
1716
|
expectExtractResult(result, { foo: ["bar"] }, []);
|
|
1969
1717
|
expect(result.invalidArgument).toBeUndefined();
|
|
1970
1718
|
|
|
1971
|
-
result = populateSubCommandValues(
|
|
1972
|
-
command,
|
|
1973
|
-
["--foo[1]", "bar1", "--foo[0]", "bar0"],
|
|
1974
|
-
undefined,
|
|
1975
|
-
);
|
|
1719
|
+
result = populateSubCommandValues(command, ["--foo[1]", "bar1", "--foo[0]", "bar0"], undefined);
|
|
1976
1720
|
expectExtractResult(result, { foo: ["bar0", "bar1"] }, []);
|
|
1977
1721
|
expect(result.invalidArgument).toBeUndefined();
|
|
1978
1722
|
|
|
1979
|
-
result = populateSubCommandValues(
|
|
1980
|
-
command,
|
|
1981
|
-
["--foo[0]=bar0", "--foo[1]", "bar1"],
|
|
1982
|
-
undefined,
|
|
1983
|
-
);
|
|
1723
|
+
result = populateSubCommandValues(command, ["--foo[0]=bar0", "--foo[1]", "bar1"], undefined);
|
|
1984
1724
|
expectExtractResult(result, { foo: ["bar0", "bar1"] }, []);
|
|
1985
1725
|
expect(result.invalidArgument).toBeUndefined();
|
|
1986
1726
|
|
|
1987
|
-
result = populateSubCommandValues(
|
|
1988
|
-
command,
|
|
1989
|
-
["--foo[1]=bar1", "-f[0]", "bar0"],
|
|
1990
|
-
undefined,
|
|
1991
|
-
);
|
|
1727
|
+
result = populateSubCommandValues(command, ["--foo[1]=bar1", "-f[0]", "bar0"], undefined);
|
|
1992
1728
|
expectExtractResult(result, { foo: ["bar0", "bar1"] }, []);
|
|
1993
1729
|
expect(result.invalidArgument).toBeUndefined();
|
|
1994
1730
|
});
|
|
@@ -1996,22 +1732,19 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
1996
1732
|
test("Option array invalid indices", () => {
|
|
1997
1733
|
const command: SubCommand = {
|
|
1998
1734
|
name: "command",
|
|
1999
|
-
options: [
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
1735
|
+
options: [
|
|
1736
|
+
{
|
|
1737
|
+
name: "foo",
|
|
1738
|
+
type: ArgumentValueTypeName.STRING,
|
|
1739
|
+
shortAlias: "f",
|
|
1740
|
+
isArray: true,
|
|
1741
|
+
},
|
|
1742
|
+
],
|
|
2005
1743
|
positionals: [],
|
|
2006
|
-
execute: async (): Promise<void> => {
|
|
2007
|
-
},
|
|
1744
|
+
execute: async (): Promise<void> => {},
|
|
2008
1745
|
};
|
|
2009
1746
|
|
|
2010
|
-
let result = populateSubCommandValues(
|
|
2011
|
-
command,
|
|
2012
|
-
["--foo[1]", "bar"],
|
|
2013
|
-
undefined,
|
|
2014
|
-
);
|
|
1747
|
+
let result = populateSubCommandValues(command, ["--foo[1]", "bar"], undefined);
|
|
2015
1748
|
let expected = {
|
|
2016
1749
|
foo: [] as Array<string>,
|
|
2017
1750
|
};
|
|
@@ -2019,11 +1752,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2019
1752
|
expectExtractResult(result, expected, []);
|
|
2020
1753
|
expect(result.invalidArgument).toBeUndefined();
|
|
2021
1754
|
|
|
2022
|
-
result = populateSubCommandValues(
|
|
2023
|
-
command,
|
|
2024
|
-
["--foo[2]", "bar2", "--foo[0]", "bar0"],
|
|
2025
|
-
undefined,
|
|
2026
|
-
);
|
|
1755
|
+
result = populateSubCommandValues(command, ["--foo[2]", "bar2", "--foo[0]", "bar0"], undefined);
|
|
2027
1756
|
expected = {
|
|
2028
1757
|
foo: [] as Array<string>,
|
|
2029
1758
|
};
|
|
@@ -2036,30 +1765,27 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2036
1765
|
test("Option array missing indices populated by configured defaults", () => {
|
|
2037
1766
|
const command: SubCommand = {
|
|
2038
1767
|
name: "command",
|
|
2039
|
-
options: [
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
1768
|
+
options: [
|
|
1769
|
+
{
|
|
1770
|
+
name: "foo",
|
|
1771
|
+
type: ArgumentValueTypeName.STRING,
|
|
1772
|
+
shortAlias: "f",
|
|
1773
|
+
isArray: true,
|
|
1774
|
+
},
|
|
1775
|
+
],
|
|
2045
1776
|
positionals: [],
|
|
2046
|
-
execute: async (): Promise<void> => {
|
|
2047
|
-
},
|
|
1777
|
+
execute: async (): Promise<void> => {},
|
|
2048
1778
|
};
|
|
2049
1779
|
|
|
2050
|
-
let result = populateSubCommandValues(
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
{ foo: ["car"] },
|
|
2054
|
-
);
|
|
1780
|
+
let result = populateSubCommandValues(command, ["--foo[1]", "bar"], {
|
|
1781
|
+
foo: ["car"],
|
|
1782
|
+
});
|
|
2055
1783
|
expectExtractResult(result, { foo: ["car", "bar"] }, []);
|
|
2056
1784
|
expect(result.invalidArgument).toBeUndefined();
|
|
2057
1785
|
|
|
2058
|
-
result = populateSubCommandValues(
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
{ foo: ["bar", "car"] },
|
|
2062
|
-
);
|
|
1786
|
+
result = populateSubCommandValues(command, ["--foo[2]", "bar1", "--foo[0]", "bar0"], {
|
|
1787
|
+
foo: ["bar", "car"],
|
|
1788
|
+
});
|
|
2063
1789
|
expectExtractResult(result, { foo: ["bar0", "car", "bar1"] }, []);
|
|
2064
1790
|
expect(result.invalidArgument).toBeUndefined();
|
|
2065
1791
|
});
|
|
@@ -2067,104 +1793,112 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2067
1793
|
test("Option array using indices either side of positional", () => {
|
|
2068
1794
|
let command: SubCommand = {
|
|
2069
1795
|
name: "command",
|
|
2070
|
-
options: [
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
1796
|
+
options: [
|
|
1797
|
+
{
|
|
1798
|
+
name: "foo",
|
|
1799
|
+
isArray: true,
|
|
1800
|
+
type: ArgumentValueTypeName.STRING,
|
|
1801
|
+
},
|
|
1802
|
+
],
|
|
1803
|
+
positionals: [
|
|
1804
|
+
{
|
|
1805
|
+
name: "goo",
|
|
1806
|
+
type: ArgumentValueTypeName.STRING,
|
|
1807
|
+
},
|
|
1808
|
+
],
|
|
1809
|
+
execute: async (): Promise<void> => {},
|
|
2081
1810
|
};
|
|
2082
1811
|
|
|
2083
1812
|
let result = populateSubCommandValues(
|
|
2084
1813
|
command,
|
|
2085
|
-
[
|
|
2086
|
-
"--foo[0]",
|
|
2087
|
-
"f1",
|
|
2088
|
-
"goo1",
|
|
2089
|
-
"--foo[1]",
|
|
2090
|
-
"f2",
|
|
2091
|
-
],
|
|
1814
|
+
["--foo[0]", "f1", "goo1", "--foo[1]", "f2"],
|
|
2092
1815
|
undefined,
|
|
2093
1816
|
);
|
|
2094
|
-
expectExtractResult(
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
1817
|
+
expectExtractResult(
|
|
1818
|
+
result,
|
|
1819
|
+
{
|
|
1820
|
+
foo: ["f1", "f2"],
|
|
1821
|
+
goo: "goo1",
|
|
1822
|
+
},
|
|
1823
|
+
[],
|
|
1824
|
+
);
|
|
2098
1825
|
expect(result.invalidArgument).toBeUndefined();
|
|
2099
1826
|
|
|
2100
1827
|
command = {
|
|
2101
1828
|
name: "command",
|
|
2102
|
-
options: [
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
1829
|
+
options: [
|
|
1830
|
+
{
|
|
1831
|
+
name: "foo",
|
|
1832
|
+
isArray: true,
|
|
1833
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
1834
|
+
},
|
|
1835
|
+
],
|
|
1836
|
+
positionals: [
|
|
1837
|
+
{
|
|
1838
|
+
name: "goo",
|
|
1839
|
+
type: ArgumentValueTypeName.STRING,
|
|
1840
|
+
},
|
|
1841
|
+
],
|
|
1842
|
+
execute: async (): Promise<void> => {},
|
|
2113
1843
|
};
|
|
2114
1844
|
result = populateSubCommandValues(
|
|
2115
1845
|
command,
|
|
2116
|
-
[
|
|
2117
|
-
"--foo[1]",
|
|
2118
|
-
"true",
|
|
2119
|
-
"goo1",
|
|
2120
|
-
"--foo[0]",
|
|
2121
|
-
"false",
|
|
2122
|
-
],
|
|
1846
|
+
["--foo[1]", "true", "goo1", "--foo[0]", "false"],
|
|
2123
1847
|
undefined,
|
|
2124
1848
|
);
|
|
2125
|
-
expectExtractResult(
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
1849
|
+
expectExtractResult(
|
|
1850
|
+
result,
|
|
1851
|
+
{
|
|
1852
|
+
foo: ["false", "true"],
|
|
1853
|
+
goo: "goo1",
|
|
1854
|
+
},
|
|
1855
|
+
[],
|
|
1856
|
+
);
|
|
2129
1857
|
expect(result.invalidArgument).toBeUndefined();
|
|
2130
1858
|
|
|
2131
|
-
result = populateSubCommandValues(
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
1859
|
+
result = populateSubCommandValues(command, ["--foo[1]", "goo1", "--foo[0]"], undefined);
|
|
1860
|
+
expectExtractResult(
|
|
1861
|
+
result,
|
|
1862
|
+
{
|
|
1863
|
+
foo: ["true", "true"],
|
|
1864
|
+
goo: "goo1",
|
|
1865
|
+
},
|
|
1866
|
+
[],
|
|
2135
1867
|
);
|
|
2136
|
-
expectExtractResult(result, {
|
|
2137
|
-
foo: ["true", "true"],
|
|
2138
|
-
goo: "goo1",
|
|
2139
|
-
}, []);
|
|
2140
1868
|
expect(result.invalidArgument).toBeUndefined();
|
|
2141
1869
|
});
|
|
2142
1870
|
|
|
2143
1871
|
test("Option complex values", () => {
|
|
2144
1872
|
const command: SubCommand = {
|
|
2145
1873
|
name: "command",
|
|
2146
|
-
options: [
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
shortAlias: "a",
|
|
2150
|
-
properties: [{
|
|
2151
|
-
name: "beta",
|
|
1874
|
+
options: [
|
|
1875
|
+
{
|
|
1876
|
+
name: "alpha",
|
|
2152
1877
|
type: ComplexValueTypeName.COMPLEX,
|
|
2153
|
-
shortAlias: "
|
|
2154
|
-
properties: [
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
1878
|
+
shortAlias: "a",
|
|
1879
|
+
properties: [
|
|
1880
|
+
{
|
|
1881
|
+
name: "beta",
|
|
1882
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
1883
|
+
shortAlias: "b",
|
|
1884
|
+
properties: [
|
|
1885
|
+
{
|
|
1886
|
+
name: "gamma",
|
|
1887
|
+
type: ArgumentValueTypeName.STRING,
|
|
1888
|
+
shortAlias: "g",
|
|
1889
|
+
},
|
|
1890
|
+
{
|
|
1891
|
+
name: "delta",
|
|
1892
|
+
type: ArgumentValueTypeName.STRING,
|
|
1893
|
+
shortAlias: "d",
|
|
1894
|
+
},
|
|
1895
|
+
],
|
|
1896
|
+
},
|
|
1897
|
+
],
|
|
1898
|
+
},
|
|
1899
|
+
],
|
|
2165
1900
|
positionals: [],
|
|
2166
|
-
execute: async (): Promise<void> => {
|
|
2167
|
-
},
|
|
1901
|
+
execute: async (): Promise<void> => {},
|
|
2168
1902
|
};
|
|
2169
1903
|
|
|
2170
1904
|
let result = populateSubCommandValues(
|
|
@@ -2172,49 +1906,59 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2172
1906
|
["--alpha.beta.gamma", "foo", "--alpha.beta.delta", "bar"],
|
|
2173
1907
|
undefined,
|
|
2174
1908
|
);
|
|
2175
|
-
expectExtractResult(
|
|
2176
|
-
|
|
2177
|
-
|
|
1909
|
+
expectExtractResult(
|
|
1910
|
+
result,
|
|
1911
|
+
{
|
|
1912
|
+
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
1913
|
+
},
|
|
1914
|
+
[],
|
|
1915
|
+
);
|
|
2178
1916
|
expect(result.invalidArgument).toBeUndefined();
|
|
2179
1917
|
|
|
2180
|
-
result = populateSubCommandValues(
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
1918
|
+
result = populateSubCommandValues(command, ["-a.b.g", "foo", "-a.b.d", "bar"], undefined);
|
|
1919
|
+
expectExtractResult(
|
|
1920
|
+
result,
|
|
1921
|
+
{
|
|
1922
|
+
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
1923
|
+
},
|
|
1924
|
+
[],
|
|
2184
1925
|
);
|
|
2185
|
-
expectExtractResult(result, {
|
|
2186
|
-
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
2187
|
-
}, []);
|
|
2188
1926
|
expect(result.invalidArgument).toBeUndefined();
|
|
2189
1927
|
});
|
|
2190
1928
|
|
|
2191
1929
|
test("Option arrays of complex values and vice versa", () => {
|
|
2192
1930
|
const command: SubCommand = {
|
|
2193
1931
|
name: "command",
|
|
2194
|
-
options: [
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
shortAlias: "a",
|
|
2198
|
-
isArray: true,
|
|
2199
|
-
properties: [{
|
|
2200
|
-
name: "beta",
|
|
1932
|
+
options: [
|
|
1933
|
+
{
|
|
1934
|
+
name: "alpha",
|
|
2201
1935
|
type: ComplexValueTypeName.COMPLEX,
|
|
2202
|
-
shortAlias: "
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
1936
|
+
shortAlias: "a",
|
|
1937
|
+
isArray: true,
|
|
1938
|
+
properties: [
|
|
1939
|
+
{
|
|
1940
|
+
name: "beta",
|
|
1941
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
1942
|
+
shortAlias: "b",
|
|
1943
|
+
properties: [
|
|
1944
|
+
{
|
|
1945
|
+
name: "gamma",
|
|
1946
|
+
type: ArgumentValueTypeName.STRING,
|
|
1947
|
+
shortAlias: "g",
|
|
1948
|
+
},
|
|
1949
|
+
{
|
|
1950
|
+
name: "delta",
|
|
1951
|
+
type: ArgumentValueTypeName.STRING,
|
|
1952
|
+
shortAlias: "d",
|
|
1953
|
+
isArray: true,
|
|
1954
|
+
},
|
|
1955
|
+
],
|
|
1956
|
+
},
|
|
1957
|
+
],
|
|
1958
|
+
},
|
|
1959
|
+
],
|
|
2215
1960
|
positionals: [],
|
|
2216
|
-
execute: async (): Promise<void> => {
|
|
2217
|
-
},
|
|
1961
|
+
execute: async (): Promise<void> => {},
|
|
2218
1962
|
};
|
|
2219
1963
|
|
|
2220
1964
|
let result = populateSubCommandValues(
|
|
@@ -2222,19 +1966,23 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2222
1966
|
["--alpha.beta.gamma", "foo", "--alpha.beta.delta", "bar"],
|
|
2223
1967
|
undefined,
|
|
2224
1968
|
);
|
|
2225
|
-
expectExtractResult(
|
|
2226
|
-
|
|
2227
|
-
|
|
1969
|
+
expectExtractResult(
|
|
1970
|
+
result,
|
|
1971
|
+
{
|
|
1972
|
+
alpha: [{ beta: { gamma: "foo", delta: ["bar"] } }],
|
|
1973
|
+
},
|
|
1974
|
+
[],
|
|
1975
|
+
);
|
|
2228
1976
|
expect(result.invalidArgument).toBeUndefined();
|
|
2229
1977
|
|
|
2230
|
-
result = populateSubCommandValues(
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
1978
|
+
result = populateSubCommandValues(command, ["-a[0].b.d[0]", "bar"], undefined);
|
|
1979
|
+
expectExtractResult(
|
|
1980
|
+
result,
|
|
1981
|
+
{
|
|
1982
|
+
alpha: [{ beta: { delta: ["bar"] } }],
|
|
1983
|
+
},
|
|
1984
|
+
[],
|
|
2234
1985
|
);
|
|
2235
|
-
expectExtractResult(result, {
|
|
2236
|
-
alpha: [{ beta: { delta: ["bar"] } }],
|
|
2237
|
-
}, []);
|
|
2238
1986
|
expect(result.invalidArgument).toBeUndefined();
|
|
2239
1987
|
|
|
2240
1988
|
result = populateSubCommandValues(
|
|
@@ -2242,9 +1990,13 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2242
1990
|
["-a[0].b.g", "foo", "-a[0].b.d[0]", "bar"],
|
|
2243
1991
|
undefined,
|
|
2244
1992
|
);
|
|
2245
|
-
expectExtractResult(
|
|
2246
|
-
|
|
2247
|
-
|
|
1993
|
+
expectExtractResult(
|
|
1994
|
+
result,
|
|
1995
|
+
{
|
|
1996
|
+
alpha: [{ beta: { gamma: "foo", delta: ["bar"] } }],
|
|
1997
|
+
},
|
|
1998
|
+
[],
|
|
1999
|
+
);
|
|
2248
2000
|
expect(result.invalidArgument).toBeUndefined();
|
|
2249
2001
|
|
|
2250
2002
|
result = populateSubCommandValues(
|
|
@@ -2265,39 +2017,52 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2265
2017
|
],
|
|
2266
2018
|
undefined,
|
|
2267
2019
|
);
|
|
2268
|
-
expectExtractResult(
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2020
|
+
expectExtractResult(
|
|
2021
|
+
result,
|
|
2022
|
+
{
|
|
2023
|
+
alpha: [
|
|
2024
|
+
{ beta: { gamma: "foo", delta: ["bar", "car"] } },
|
|
2025
|
+
{
|
|
2026
|
+
beta: { gamma: "foo", delta: ["car", "bar"] },
|
|
2027
|
+
},
|
|
2028
|
+
],
|
|
2029
|
+
},
|
|
2030
|
+
[],
|
|
2031
|
+
);
|
|
2273
2032
|
expect(result.invalidArgument).toBeUndefined();
|
|
2274
2033
|
});
|
|
2275
2034
|
|
|
2276
2035
|
test("Option complex values with invalid properties", () => {
|
|
2277
2036
|
const command: SubCommand = {
|
|
2278
2037
|
name: "command",
|
|
2279
|
-
options: [
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
shortAlias: "a",
|
|
2283
|
-
properties: [{
|
|
2284
|
-
name: "beta",
|
|
2038
|
+
options: [
|
|
2039
|
+
{
|
|
2040
|
+
name: "alpha",
|
|
2285
2041
|
type: ComplexValueTypeName.COMPLEX,
|
|
2286
|
-
shortAlias: "
|
|
2287
|
-
properties: [
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2042
|
+
shortAlias: "a",
|
|
2043
|
+
properties: [
|
|
2044
|
+
{
|
|
2045
|
+
name: "beta",
|
|
2046
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
2047
|
+
shortAlias: "b",
|
|
2048
|
+
properties: [
|
|
2049
|
+
{
|
|
2050
|
+
name: "gamma",
|
|
2051
|
+
type: ArgumentValueTypeName.STRING,
|
|
2052
|
+
shortAlias: "g",
|
|
2053
|
+
},
|
|
2054
|
+
{
|
|
2055
|
+
name: "delta",
|
|
2056
|
+
type: ArgumentValueTypeName.STRING,
|
|
2057
|
+
shortAlias: "d",
|
|
2058
|
+
},
|
|
2059
|
+
],
|
|
2060
|
+
},
|
|
2061
|
+
],
|
|
2062
|
+
},
|
|
2063
|
+
],
|
|
2298
2064
|
positionals: [],
|
|
2299
|
-
execute: async (): Promise<void> => {
|
|
2300
|
-
},
|
|
2065
|
+
execute: async (): Promise<void> => {},
|
|
2301
2066
|
};
|
|
2302
2067
|
|
|
2303
2068
|
let result = populateSubCommandValues(
|
|
@@ -2305,54 +2070,56 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2305
2070
|
["--alpha.beta.delta", "bar", "--alpha.beta.gamma"],
|
|
2306
2071
|
undefined,
|
|
2307
2072
|
);
|
|
2308
|
-
expectExtractResult(
|
|
2309
|
-
|
|
2310
|
-
|
|
2073
|
+
expectExtractResult(
|
|
2074
|
+
result,
|
|
2075
|
+
{
|
|
2076
|
+
alpha: { beta: { delta: "bar" } },
|
|
2077
|
+
},
|
|
2078
|
+
[],
|
|
2079
|
+
);
|
|
2311
2080
|
expect(result.invalidArgument).toEqual({
|
|
2312
|
-
argument:
|
|
2313
|
-
|
|
2314
|
-
.properties[0],
|
|
2081
|
+
argument: ((command.options[0] as ComplexOption).properties[0] as ComplexOption)
|
|
2082
|
+
.properties[0],
|
|
2315
2083
|
name: "--alpha.beta.gamma",
|
|
2316
2084
|
reason: InvalidArgumentReason.MISSING_VALUE,
|
|
2317
2085
|
});
|
|
2318
2086
|
|
|
2319
|
-
result = populateSubCommandValues(
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2087
|
+
result = populateSubCommandValues(command, ["-a.b.g", "foo", "--alpha.beta.delta"], undefined);
|
|
2088
|
+
expectExtractResult(
|
|
2089
|
+
result,
|
|
2090
|
+
{
|
|
2091
|
+
alpha: { beta: { gamma: "foo" } },
|
|
2092
|
+
},
|
|
2093
|
+
[],
|
|
2323
2094
|
);
|
|
2324
|
-
expectExtractResult(result, {
|
|
2325
|
-
alpha: { beta: { gamma: "foo" } },
|
|
2326
|
-
}, []);
|
|
2327
2095
|
expect(result.invalidArgument).toEqual({
|
|
2328
|
-
argument:
|
|
2329
|
-
|
|
2330
|
-
.properties[1],
|
|
2096
|
+
argument: ((command.options[0] as ComplexOption).properties[0] as ComplexOption)
|
|
2097
|
+
.properties[1],
|
|
2331
2098
|
name: "--alpha.beta.delta",
|
|
2332
2099
|
reason: InvalidArgumentReason.MISSING_VALUE,
|
|
2333
2100
|
});
|
|
2334
2101
|
|
|
2335
|
-
result = populateSubCommandValues(
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2102
|
+
result = populateSubCommandValues(command, ["-a.b.x", "foo"], undefined);
|
|
2103
|
+
expectExtractResult(
|
|
2104
|
+
result,
|
|
2105
|
+
{
|
|
2106
|
+
alpha: { beta: {} },
|
|
2107
|
+
},
|
|
2108
|
+
["foo"],
|
|
2339
2109
|
);
|
|
2340
|
-
expectExtractResult(result, {
|
|
2341
|
-
alpha: { beta: {} },
|
|
2342
|
-
}, ["foo"]);
|
|
2343
2110
|
expect(result.invalidArgument).toEqual({
|
|
2344
2111
|
name: "-a.b.x",
|
|
2345
2112
|
reason: InvalidArgumentReason.UNKNOWN_PROPERTY,
|
|
2346
2113
|
});
|
|
2347
2114
|
|
|
2348
|
-
result = populateSubCommandValues(
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2115
|
+
result = populateSubCommandValues(command, ["-a.b.g.a", "foo"], undefined);
|
|
2116
|
+
expectExtractResult(
|
|
2117
|
+
result,
|
|
2118
|
+
{
|
|
2119
|
+
alpha: { beta: {} },
|
|
2120
|
+
},
|
|
2121
|
+
["foo"],
|
|
2352
2122
|
);
|
|
2353
|
-
expectExtractResult(result, {
|
|
2354
|
-
alpha: { beta: {} },
|
|
2355
|
-
}, ["foo"]);
|
|
2356
2123
|
expect(result.invalidArgument).toEqual({
|
|
2357
2124
|
name: "-a.b.g.a",
|
|
2358
2125
|
reason: InvalidArgumentReason.UNKNOWN_PROPERTY,
|
|
@@ -2362,62 +2129,73 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2362
2129
|
test("Option complex values with missing properties supplied by configured defaults", () => {
|
|
2363
2130
|
const command: SubCommand = {
|
|
2364
2131
|
name: "command",
|
|
2365
|
-
options: [
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
shortAlias: "a",
|
|
2369
|
-
properties: [{
|
|
2370
|
-
name: "beta",
|
|
2132
|
+
options: [
|
|
2133
|
+
{
|
|
2134
|
+
name: "alpha",
|
|
2371
2135
|
type: ComplexValueTypeName.COMPLEX,
|
|
2372
|
-
shortAlias: "
|
|
2373
|
-
properties: [
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2136
|
+
shortAlias: "a",
|
|
2137
|
+
properties: [
|
|
2138
|
+
{
|
|
2139
|
+
name: "beta",
|
|
2140
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
2141
|
+
shortAlias: "b",
|
|
2142
|
+
properties: [
|
|
2143
|
+
{
|
|
2144
|
+
name: "gamma",
|
|
2145
|
+
type: ArgumentValueTypeName.STRING,
|
|
2146
|
+
shortAlias: "g",
|
|
2147
|
+
},
|
|
2148
|
+
{
|
|
2149
|
+
name: "delta",
|
|
2150
|
+
type: ArgumentValueTypeName.STRING,
|
|
2151
|
+
shortAlias: "d",
|
|
2152
|
+
},
|
|
2153
|
+
],
|
|
2154
|
+
},
|
|
2155
|
+
],
|
|
2156
|
+
},
|
|
2157
|
+
],
|
|
2384
2158
|
positionals: [],
|
|
2385
|
-
execute: async (): Promise<void> => {
|
|
2386
|
-
},
|
|
2159
|
+
execute: async (): Promise<void> => {},
|
|
2387
2160
|
};
|
|
2388
2161
|
|
|
2389
|
-
let result = populateSubCommandValues(
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2162
|
+
let result = populateSubCommandValues(command, ["--alpha.beta.delta", "bar"], {
|
|
2163
|
+
alpha: { beta: { gamma: "foo" } },
|
|
2164
|
+
});
|
|
2165
|
+
expectExtractResult(
|
|
2166
|
+
result,
|
|
2167
|
+
{
|
|
2168
|
+
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
2169
|
+
},
|
|
2170
|
+
[],
|
|
2393
2171
|
);
|
|
2394
|
-
expectExtractResult(result, {
|
|
2395
|
-
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
2396
|
-
}, []);
|
|
2397
2172
|
expect(result.invalidArgument).toBeUndefined();
|
|
2398
2173
|
|
|
2399
|
-
result = populateSubCommandValues(
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2174
|
+
result = populateSubCommandValues(command, ["-a.b.g", "foo"], {
|
|
2175
|
+
alpha: { beta: { delta: "bar" } },
|
|
2176
|
+
});
|
|
2177
|
+
expectExtractResult(
|
|
2178
|
+
result,
|
|
2179
|
+
{
|
|
2180
|
+
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
2181
|
+
},
|
|
2182
|
+
[],
|
|
2403
2183
|
);
|
|
2404
|
-
expectExtractResult(result, {
|
|
2405
|
-
alpha: { beta: { gamma: "foo", delta: "bar" } },
|
|
2406
|
-
}, []);
|
|
2407
2184
|
expect(result.invalidArgument).toBeUndefined();
|
|
2408
2185
|
});
|
|
2409
2186
|
|
|
2410
2187
|
test("Option array check for maximum array size", () => {
|
|
2411
2188
|
const command: SubCommand = {
|
|
2412
2189
|
name: "command",
|
|
2413
|
-
options: [
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2190
|
+
options: [
|
|
2191
|
+
{
|
|
2192
|
+
name: "foo",
|
|
2193
|
+
type: ArgumentValueTypeName.STRING,
|
|
2194
|
+
isArray: true,
|
|
2195
|
+
},
|
|
2196
|
+
],
|
|
2418
2197
|
positionals: [],
|
|
2419
|
-
execute: async (): Promise<void> => {
|
|
2420
|
-
},
|
|
2198
|
+
execute: async (): Promise<void> => {},
|
|
2421
2199
|
};
|
|
2422
2200
|
|
|
2423
2201
|
const potentialArgs: Array<string> = [];
|
|
@@ -2429,11 +2207,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2429
2207
|
values.foo.push(`bar${i}`);
|
|
2430
2208
|
}
|
|
2431
2209
|
|
|
2432
|
-
let result = populateSubCommandValues(
|
|
2433
|
-
command,
|
|
2434
|
-
potentialArgs,
|
|
2435
|
-
undefined,
|
|
2436
|
-
);
|
|
2210
|
+
let result = populateSubCommandValues(command, potentialArgs, undefined);
|
|
2437
2211
|
expectExtractResult(result, values, ["--foo=bar256"]);
|
|
2438
2212
|
expect(result.invalidArgument).toEqual({
|
|
2439
2213
|
argument: command.options[0],
|
|
@@ -2441,11 +2215,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2441
2215
|
name: "foo",
|
|
2442
2216
|
});
|
|
2443
2217
|
|
|
2444
|
-
result = populateSubCommandValues(
|
|
2445
|
-
command,
|
|
2446
|
-
["--foo[256]=bar"],
|
|
2447
|
-
undefined,
|
|
2448
|
-
);
|
|
2218
|
+
result = populateSubCommandValues(command, ["--foo[256]=bar"], undefined);
|
|
2449
2219
|
expectExtractResult(result, {}, []);
|
|
2450
2220
|
expect(result.invalidArgument).toEqual({
|
|
2451
2221
|
argument: command.options[0],
|
|
@@ -2453,11 +2223,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2453
2223
|
name: "foo",
|
|
2454
2224
|
});
|
|
2455
2225
|
|
|
2456
|
-
result = populateSubCommandValues(
|
|
2457
|
-
command,
|
|
2458
|
-
["--foo[256]", "bar"],
|
|
2459
|
-
undefined,
|
|
2460
|
-
);
|
|
2226
|
+
result = populateSubCommandValues(command, ["--foo[256]", "bar"], undefined);
|
|
2461
2227
|
expectExtractResult(result, {}, ["bar"]);
|
|
2462
2228
|
expect(result.invalidArgument).toEqual({
|
|
2463
2229
|
argument: command.options[0],
|
|
@@ -2469,15 +2235,16 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2469
2235
|
test("Option array using mix of explicit and implicit indices", () => {
|
|
2470
2236
|
const command: SubCommand = {
|
|
2471
2237
|
name: "command",
|
|
2472
|
-
options: [
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2238
|
+
options: [
|
|
2239
|
+
{
|
|
2240
|
+
name: "foo",
|
|
2241
|
+
type: ArgumentValueTypeName.STRING,
|
|
2242
|
+
shortAlias: "f",
|
|
2243
|
+
isArray: true,
|
|
2244
|
+
},
|
|
2245
|
+
],
|
|
2478
2246
|
positionals: [],
|
|
2479
|
-
execute: async (): Promise<void> => {
|
|
2480
|
-
},
|
|
2247
|
+
execute: async (): Promise<void> => {},
|
|
2481
2248
|
};
|
|
2482
2249
|
|
|
2483
2250
|
let result = populateSubCommandValues(
|
|
@@ -2496,11 +2263,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2496
2263
|
expectExtractResult(result, { foo: ["bar0", "bar1", "bar2"] }, []);
|
|
2497
2264
|
expect(result.invalidArgument).toBeUndefined();
|
|
2498
2265
|
|
|
2499
|
-
result = populateSubCommandValues(
|
|
2500
|
-
command,
|
|
2501
|
-
["--foo[2]", "bar2", "--foo", "bar3"],
|
|
2502
|
-
undefined,
|
|
2503
|
-
);
|
|
2266
|
+
result = populateSubCommandValues(command, ["--foo[2]", "bar2", "--foo", "bar3"], undefined);
|
|
2504
2267
|
|
|
2505
2268
|
const values = { foo: [] as Array<string | undefined> };
|
|
2506
2269
|
values.foo[2] = "bar2";
|
|
@@ -2514,13 +2277,14 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2514
2277
|
const command: SubCommand = {
|
|
2515
2278
|
name: "command",
|
|
2516
2279
|
options: [],
|
|
2517
|
-
positionals: [
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2280
|
+
positionals: [
|
|
2281
|
+
{
|
|
2282
|
+
name: "foo",
|
|
2283
|
+
type: ArgumentValueTypeName.STRING,
|
|
2284
|
+
isVarargMultiple: true,
|
|
2285
|
+
},
|
|
2286
|
+
],
|
|
2287
|
+
execute: async (): Promise<void> => {},
|
|
2524
2288
|
};
|
|
2525
2289
|
|
|
2526
2290
|
const potentialArgs: Array<string> = [];
|
|
@@ -2532,11 +2296,7 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2532
2296
|
values.foo.push(`bar${i}`);
|
|
2533
2297
|
}
|
|
2534
2298
|
|
|
2535
|
-
const result = populateSubCommandValues(
|
|
2536
|
-
command,
|
|
2537
|
-
potentialArgs,
|
|
2538
|
-
undefined,
|
|
2539
|
-
);
|
|
2299
|
+
const result = populateSubCommandValues(command, potentialArgs, undefined);
|
|
2540
2300
|
expectExtractResult(result, values, ["bar256"]);
|
|
2541
2301
|
expect(result.invalidArgument).toEqual({
|
|
2542
2302
|
argument: command.positionals[0],
|
|
@@ -2548,38 +2308,44 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2548
2308
|
test("Option path invalid reference to complex option", () => {
|
|
2549
2309
|
const command: SubCommand = {
|
|
2550
2310
|
name: "command",
|
|
2551
|
-
options: [
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
shortAlias: "a",
|
|
2555
|
-
properties: [{
|
|
2556
|
-
name: "beta",
|
|
2311
|
+
options: [
|
|
2312
|
+
{
|
|
2313
|
+
name: "alpha",
|
|
2557
2314
|
type: ComplexValueTypeName.COMPLEX,
|
|
2558
|
-
shortAlias: "
|
|
2559
|
-
properties: [
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2315
|
+
shortAlias: "a",
|
|
2316
|
+
properties: [
|
|
2317
|
+
{
|
|
2318
|
+
name: "beta",
|
|
2319
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
2320
|
+
shortAlias: "b",
|
|
2321
|
+
properties: [
|
|
2322
|
+
{
|
|
2323
|
+
name: "gamma",
|
|
2324
|
+
type: ArgumentValueTypeName.STRING,
|
|
2325
|
+
shortAlias: "g",
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
name: "delta",
|
|
2329
|
+
type: ArgumentValueTypeName.STRING,
|
|
2330
|
+
shortAlias: "d",
|
|
2331
|
+
},
|
|
2332
|
+
],
|
|
2333
|
+
},
|
|
2334
|
+
],
|
|
2335
|
+
},
|
|
2336
|
+
],
|
|
2570
2337
|
positionals: [],
|
|
2571
|
-
execute: async (): Promise<void> => {
|
|
2572
|
-
},
|
|
2338
|
+
execute: async (): Promise<void> => {},
|
|
2573
2339
|
};
|
|
2574
2340
|
|
|
2575
|
-
const result = populateSubCommandValues(
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2341
|
+
const result = populateSubCommandValues(command, ["--alpha.beta", "foo"], undefined);
|
|
2342
|
+
expectExtractResult(
|
|
2343
|
+
result,
|
|
2344
|
+
{
|
|
2345
|
+
alpha: { beta: {} },
|
|
2346
|
+
},
|
|
2347
|
+
["foo"],
|
|
2579
2348
|
);
|
|
2580
|
-
expectExtractResult(result, {
|
|
2581
|
-
alpha: { beta: {} },
|
|
2582
|
-
}, ["foo"]);
|
|
2583
2349
|
expect(result.invalidArgument).toEqual({
|
|
2584
2350
|
argument: (command.options[0] as ComplexOption).properties[0],
|
|
2585
2351
|
reason: InvalidArgumentReason.OPTION_IS_COMPLEX,
|
|
@@ -2590,65 +2356,71 @@ describe("subCommandValuePopulation tests", () => {
|
|
|
2590
2356
|
test("Complex options with duplicated names and aliases ok if not siblings", () => {
|
|
2591
2357
|
const command: SubCommand = {
|
|
2592
2358
|
name: "command",
|
|
2593
|
-
options: [
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
shortAlias: "a",
|
|
2597
|
-
properties: [{
|
|
2598
|
-
name: "beta",
|
|
2359
|
+
options: [
|
|
2360
|
+
{
|
|
2361
|
+
name: "alpha",
|
|
2599
2362
|
type: ComplexValueTypeName.COMPLEX,
|
|
2600
|
-
shortAlias: "
|
|
2601
|
-
properties: [
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2363
|
+
shortAlias: "a",
|
|
2364
|
+
properties: [
|
|
2365
|
+
{
|
|
2366
|
+
name: "beta",
|
|
2367
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
2368
|
+
shortAlias: "b",
|
|
2369
|
+
properties: [
|
|
2370
|
+
{
|
|
2371
|
+
name: "alpha",
|
|
2372
|
+
type: ArgumentValueTypeName.STRING,
|
|
2373
|
+
shortAlias: "a",
|
|
2374
|
+
},
|
|
2375
|
+
],
|
|
2376
|
+
},
|
|
2377
|
+
],
|
|
2378
|
+
},
|
|
2379
|
+
],
|
|
2608
2380
|
positionals: [],
|
|
2609
|
-
execute: async (): Promise<void> => {
|
|
2610
|
-
},
|
|
2381
|
+
execute: async (): Promise<void> => {},
|
|
2611
2382
|
};
|
|
2612
2383
|
|
|
2613
|
-
const result = populateSubCommandValues(
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2384
|
+
const result = populateSubCommandValues(command, ["-a.b.a", "foo"], undefined);
|
|
2385
|
+
expectExtractResult(
|
|
2386
|
+
result,
|
|
2387
|
+
{
|
|
2388
|
+
alpha: { beta: { alpha: "foo" } },
|
|
2389
|
+
},
|
|
2390
|
+
[],
|
|
2617
2391
|
);
|
|
2618
|
-
expectExtractResult(result, {
|
|
2619
|
-
alpha: { beta: { alpha: "foo" } },
|
|
2620
|
-
}, []);
|
|
2621
2392
|
expect(result.invalidArgument).toBeUndefined();
|
|
2622
2393
|
});
|
|
2623
2394
|
|
|
2624
2395
|
test("Option path check for maximum nesting", () => {
|
|
2625
2396
|
const command: SubCommand = {
|
|
2626
2397
|
name: "command",
|
|
2627
|
-
options: [
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
shortAlias: "a",
|
|
2631
|
-
properties: [{
|
|
2632
|
-
name: "beta",
|
|
2398
|
+
options: [
|
|
2399
|
+
{
|
|
2400
|
+
name: "alpha",
|
|
2633
2401
|
type: ComplexValueTypeName.COMPLEX,
|
|
2634
|
-
shortAlias: "
|
|
2635
|
-
properties: [
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2402
|
+
shortAlias: "a",
|
|
2403
|
+
properties: [
|
|
2404
|
+
{
|
|
2405
|
+
name: "beta",
|
|
2406
|
+
type: ComplexValueTypeName.COMPLEX,
|
|
2407
|
+
shortAlias: "b",
|
|
2408
|
+
properties: [
|
|
2409
|
+
{
|
|
2410
|
+
name: "gamma",
|
|
2411
|
+
type: ArgumentValueTypeName.STRING,
|
|
2412
|
+
shortAlias: "g",
|
|
2413
|
+
},
|
|
2414
|
+
],
|
|
2415
|
+
},
|
|
2416
|
+
],
|
|
2417
|
+
},
|
|
2418
|
+
],
|
|
2642
2419
|
positionals: [],
|
|
2643
|
-
execute: async (): Promise<void> => {
|
|
2644
|
-
},
|
|
2420
|
+
execute: async (): Promise<void> => {},
|
|
2645
2421
|
};
|
|
2646
2422
|
|
|
2647
|
-
const result = populateSubCommandValues(
|
|
2648
|
-
command,
|
|
2649
|
-
["-a.b.g.d.e.f.g.h.i.j.k", "foo"],
|
|
2650
|
-
undefined,
|
|
2651
|
-
);
|
|
2423
|
+
const result = populateSubCommandValues(command, ["-a.b.g.d.e.f.g.h.i.j.k", "foo"], undefined);
|
|
2652
2424
|
expectExtractResult(result, {}, ["foo"]);
|
|
2653
2425
|
expect(result.invalidArgument).toEqual({
|
|
2654
2426
|
reason: InvalidArgumentReason.NESTING_DEPTH_EXCEEDED,
|