@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
|
@@ -19,48 +19,31 @@ import type Command from "../../src/api/command/Command.ts";
|
|
|
19
19
|
|
|
20
20
|
function expectScanResult(result: ScanResult, expected: ScanResult) {
|
|
21
21
|
expect(result.unusedArgSequences).toEqual(expected.unusedArgSequences);
|
|
22
|
-
expect(
|
|
23
|
-
|
|
24
|
-
).toEqual(
|
|
25
|
-
expected.nonModifierCommandClause!,
|
|
26
|
-
);
|
|
27
|
-
expect(
|
|
28
|
-
result.globalModifierCommandClauses,
|
|
29
|
-
).toEqual(
|
|
30
|
-
expected.globalModifierCommandClauses!,
|
|
31
|
-
);
|
|
22
|
+
expect(result.nonModifierCommandClause).toEqual(expected.nonModifierCommandClause!);
|
|
23
|
+
expect(result.globalModifierCommandClauses).toEqual(expected.globalModifierCommandClauses!);
|
|
32
24
|
}
|
|
33
25
|
describe("scanner tests", () => {
|
|
34
26
|
test("Global modifier command scanned", () => {
|
|
35
|
-
const globalModifierCommand = getGlobalModifierCommand(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
string,
|
|
43
|
-
GlobalModifierCommand
|
|
44
|
-
> = new Map([[globalModifierCommand.name, globalModifierCommand]]);
|
|
45
|
-
const globalModifierCommandsByShortAlias: ReadonlyMap<
|
|
46
|
-
string,
|
|
47
|
-
GlobalModifierCommand
|
|
48
|
-
> = new Map([[globalModifierCommand.shortAlias!, globalModifierCommand]]);
|
|
27
|
+
const globalModifierCommand = getGlobalModifierCommand("modifier", "m", true, true);
|
|
28
|
+
const globalModifierCommandsByName: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
29
|
+
[globalModifierCommand.name, globalModifierCommand],
|
|
30
|
+
]);
|
|
31
|
+
const globalModifierCommandsByShortAlias: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
32
|
+
[globalModifierCommand.shortAlias!, globalModifierCommand],
|
|
33
|
+
]);
|
|
49
34
|
|
|
50
35
|
const expected: ScanResult = {
|
|
51
|
-
globalModifierCommandClauses: [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
globalModifierCommandClauses: [
|
|
37
|
+
{
|
|
38
|
+
command: globalModifierCommand,
|
|
39
|
+
potentialArgs: ["g", "bar"],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
55
42
|
unusedArgSequences: [],
|
|
56
43
|
};
|
|
57
44
|
|
|
58
45
|
let scanResult = scanForGlobalModifierCommandClauses(
|
|
59
|
-
[[
|
|
60
|
-
"--modifier",
|
|
61
|
-
"g",
|
|
62
|
-
"bar",
|
|
63
|
-
]],
|
|
46
|
+
[["--modifier", "g", "bar"]],
|
|
64
47
|
globalModifierCommandsByName,
|
|
65
48
|
globalModifierCommandsByShortAlias,
|
|
66
49
|
);
|
|
@@ -88,22 +71,14 @@ describe("scanner tests", () => {
|
|
|
88
71
|
expectScanResult(scanResult, expected);
|
|
89
72
|
|
|
90
73
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
91
|
-
[[], [
|
|
92
|
-
"--modifier",
|
|
93
|
-
"g",
|
|
94
|
-
"bar",
|
|
95
|
-
]],
|
|
74
|
+
[[], ["--modifier", "g", "bar"]],
|
|
96
75
|
globalModifierCommandsByName,
|
|
97
76
|
globalModifierCommandsByShortAlias,
|
|
98
77
|
);
|
|
99
78
|
expectScanResult(scanResult, expected);
|
|
100
79
|
|
|
101
80
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
102
|
-
[[
|
|
103
|
-
"--modifier",
|
|
104
|
-
"g",
|
|
105
|
-
"bar",
|
|
106
|
-
], []],
|
|
81
|
+
[["--modifier", "g", "bar"], []],
|
|
107
82
|
globalModifierCommandsByName,
|
|
108
83
|
globalModifierCommandsByShortAlias,
|
|
109
84
|
);
|
|
@@ -111,127 +86,85 @@ describe("scanner tests", () => {
|
|
|
111
86
|
});
|
|
112
87
|
|
|
113
88
|
test("Two global modifier commands scanned", () => {
|
|
114
|
-
const globalModifierCommand1 = getGlobalModifierCommand(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
true,
|
|
118
|
-
true,
|
|
119
|
-
);
|
|
120
|
-
const globalModifierCommand2 = getGlobalModifierCommand(
|
|
121
|
-
"modifier2",
|
|
122
|
-
"2",
|
|
123
|
-
true,
|
|
124
|
-
true,
|
|
125
|
-
);
|
|
126
|
-
const globalModifierCommandsByName: ReadonlyMap<
|
|
127
|
-
string,
|
|
128
|
-
GlobalModifierCommand
|
|
129
|
-
> = new Map([
|
|
89
|
+
const globalModifierCommand1 = getGlobalModifierCommand("modifier1", "1", true, true);
|
|
90
|
+
const globalModifierCommand2 = getGlobalModifierCommand("modifier2", "2", true, true);
|
|
91
|
+
const globalModifierCommandsByName: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
130
92
|
[globalModifierCommand1.name, globalModifierCommand1],
|
|
131
93
|
[globalModifierCommand2.name, globalModifierCommand2],
|
|
132
94
|
]);
|
|
133
|
-
const globalModifierCommandsByShortAlias: ReadonlyMap<
|
|
134
|
-
string,
|
|
135
|
-
GlobalModifierCommand
|
|
136
|
-
> = new Map([
|
|
95
|
+
const globalModifierCommandsByShortAlias: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
137
96
|
[globalModifierCommand1.shortAlias!, globalModifierCommand1],
|
|
138
97
|
[globalModifierCommand2.shortAlias!, globalModifierCommand2],
|
|
139
98
|
]);
|
|
140
99
|
|
|
141
100
|
let expected: ScanResult = {
|
|
142
|
-
globalModifierCommandClauses: [
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
101
|
+
globalModifierCommandClauses: [
|
|
102
|
+
{
|
|
103
|
+
command: globalModifierCommand1,
|
|
104
|
+
potentialArgs: ["g", "bar"],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
command: globalModifierCommand2,
|
|
108
|
+
potentialArgs: ["g", "bar"],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
149
111
|
unusedArgSequences: [],
|
|
150
112
|
};
|
|
151
113
|
|
|
152
114
|
let scanResult = scanForGlobalModifierCommandClauses(
|
|
153
|
-
[[
|
|
154
|
-
"--modifier1",
|
|
155
|
-
"g",
|
|
156
|
-
"bar",
|
|
157
|
-
"--modifier2",
|
|
158
|
-
"g",
|
|
159
|
-
"bar",
|
|
160
|
-
]],
|
|
115
|
+
[["--modifier1", "g", "bar", "--modifier2", "g", "bar"]],
|
|
161
116
|
globalModifierCommandsByName,
|
|
162
117
|
globalModifierCommandsByShortAlias,
|
|
163
118
|
);
|
|
164
119
|
expectScanResult(scanResult, expected);
|
|
165
120
|
|
|
166
121
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
167
|
-
[[
|
|
168
|
-
"--modifier1=g",
|
|
169
|
-
"bar",
|
|
170
|
-
"--modifier2=g",
|
|
171
|
-
"bar",
|
|
172
|
-
]],
|
|
122
|
+
[["--modifier1=g", "bar", "--modifier2=g", "bar"]],
|
|
173
123
|
globalModifierCommandsByName,
|
|
174
124
|
globalModifierCommandsByShortAlias,
|
|
175
125
|
);
|
|
176
126
|
expectScanResult(scanResult, expected);
|
|
177
127
|
|
|
178
128
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
179
|
-
[[
|
|
180
|
-
"-1",
|
|
181
|
-
"g",
|
|
182
|
-
"bar",
|
|
183
|
-
"-2",
|
|
184
|
-
"g",
|
|
185
|
-
"bar",
|
|
186
|
-
]],
|
|
129
|
+
[["-1", "g", "bar", "-2", "g", "bar"]],
|
|
187
130
|
globalModifierCommandsByName,
|
|
188
131
|
globalModifierCommandsByShortAlias,
|
|
189
132
|
);
|
|
190
133
|
expectScanResult(scanResult, expected);
|
|
191
134
|
|
|
192
135
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
193
|
-
[[
|
|
194
|
-
"-1=g",
|
|
195
|
-
"bar",
|
|
196
|
-
"-2=g",
|
|
197
|
-
"bar",
|
|
198
|
-
]],
|
|
136
|
+
[["-1=g", "bar", "-2=g", "bar"]],
|
|
199
137
|
globalModifierCommandsByName,
|
|
200
138
|
globalModifierCommandsByShortAlias,
|
|
201
139
|
);
|
|
202
140
|
expectScanResult(scanResult, expected);
|
|
203
141
|
|
|
204
142
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
205
|
-
[[], [
|
|
206
|
-
"-1=g",
|
|
207
|
-
"bar",
|
|
208
|
-
"-2=g",
|
|
209
|
-
"bar",
|
|
210
|
-
]],
|
|
143
|
+
[[], ["-1=g", "bar", "-2=g", "bar"]],
|
|
211
144
|
globalModifierCommandsByName,
|
|
212
145
|
globalModifierCommandsByShortAlias,
|
|
213
146
|
);
|
|
214
147
|
expectScanResult(scanResult, expected);
|
|
215
148
|
|
|
216
149
|
expected = {
|
|
217
|
-
globalModifierCommandClauses: [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
150
|
+
globalModifierCommandClauses: [
|
|
151
|
+
{
|
|
152
|
+
command: globalModifierCommand1,
|
|
153
|
+
potentialArgs: ["g", "bar"],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
command: globalModifierCommand2,
|
|
157
|
+
potentialArgs: ["g", "bar"],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
224
160
|
unusedArgSequences: [],
|
|
225
161
|
};
|
|
226
162
|
|
|
227
163
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
228
|
-
[
|
|
229
|
-
"-1=g",
|
|
230
|
-
"bar",
|
|
231
|
-
],
|
|
232
|
-
"-2=g",
|
|
233
|
-
"bar",
|
|
234
|
-
]],
|
|
164
|
+
[
|
|
165
|
+
["-1=g", "bar"],
|
|
166
|
+
["-2=g", "bar"],
|
|
167
|
+
],
|
|
235
168
|
globalModifierCommandsByName,
|
|
236
169
|
globalModifierCommandsByShortAlias,
|
|
237
170
|
);
|
|
@@ -239,110 +172,71 @@ describe("scanner tests", () => {
|
|
|
239
172
|
});
|
|
240
173
|
|
|
241
174
|
test("Unused leading args whilst scanning for global modifier command", () => {
|
|
242
|
-
const globalModifierCommand = getGlobalModifierCommand(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
string,
|
|
250
|
-
GlobalModifierCommand
|
|
251
|
-
> = new Map([[globalModifierCommand.name, globalModifierCommand]]);
|
|
252
|
-
const globalModifierCommandsByShortAlias: ReadonlyMap<
|
|
253
|
-
string,
|
|
254
|
-
GlobalModifierCommand
|
|
255
|
-
> = new Map([[globalModifierCommand.shortAlias!, globalModifierCommand]]);
|
|
175
|
+
const globalModifierCommand = getGlobalModifierCommand("modifier", "m", true, true);
|
|
176
|
+
const globalModifierCommandsByName: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
177
|
+
[globalModifierCommand.name, globalModifierCommand],
|
|
178
|
+
]);
|
|
179
|
+
const globalModifierCommandsByShortAlias: ReadonlyMap<string, GlobalModifierCommand> = new Map([
|
|
180
|
+
[globalModifierCommand.shortAlias!, globalModifierCommand],
|
|
181
|
+
]);
|
|
256
182
|
|
|
257
183
|
let scanResult = scanForGlobalModifierCommandClauses(
|
|
258
|
-
[[
|
|
259
|
-
"hello",
|
|
260
|
-
"--world",
|
|
261
|
-
"subCommand",
|
|
262
|
-
"bar",
|
|
263
|
-
"--goo",
|
|
264
|
-
"g",
|
|
265
|
-
"--modifier",
|
|
266
|
-
"g",
|
|
267
|
-
"bar",
|
|
268
|
-
]],
|
|
184
|
+
[["hello", "--world", "subCommand", "bar", "--goo", "g", "--modifier", "g", "bar"]],
|
|
269
185
|
globalModifierCommandsByName,
|
|
270
186
|
globalModifierCommandsByShortAlias,
|
|
271
187
|
);
|
|
272
188
|
expectScanResult(scanResult, {
|
|
273
|
-
globalModifierCommandClauses: [
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
"subCommand",
|
|
281
|
-
"bar",
|
|
282
|
-
"--goo",
|
|
283
|
-
"g",
|
|
284
|
-
]],
|
|
189
|
+
globalModifierCommandClauses: [
|
|
190
|
+
{
|
|
191
|
+
command: globalModifierCommand,
|
|
192
|
+
potentialArgs: ["g", "bar"],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
unusedArgSequences: [["hello", "--world", "subCommand", "bar", "--goo", "g"]],
|
|
285
196
|
});
|
|
286
197
|
|
|
287
198
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
288
|
-
[[
|
|
289
|
-
"hello",
|
|
290
|
-
"--world",
|
|
291
|
-
"--modifier",
|
|
292
|
-
"g",
|
|
293
|
-
"bar",
|
|
294
|
-
"--globalCommand",
|
|
295
|
-
"bar",
|
|
296
|
-
"--goo",
|
|
297
|
-
"g",
|
|
298
|
-
]],
|
|
199
|
+
[["hello", "--world", "--modifier", "g", "bar", "--globalCommand", "bar", "--goo", "g"]],
|
|
299
200
|
globalModifierCommandsByName,
|
|
300
201
|
globalModifierCommandsByShortAlias,
|
|
301
202
|
);
|
|
302
203
|
expectScanResult(scanResult, {
|
|
303
|
-
globalModifierCommandClauses: [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
204
|
+
globalModifierCommandClauses: [
|
|
205
|
+
{
|
|
206
|
+
command: globalModifierCommand,
|
|
207
|
+
potentialArgs: ["g", "bar", "--globalCommand", "bar", "--goo", "g"],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
307
210
|
unusedArgSequences: [["hello", "--world"]],
|
|
308
211
|
});
|
|
309
212
|
scanResult = scanForGlobalModifierCommandClauses(
|
|
310
|
-
[
|
|
311
|
-
"hello",
|
|
312
|
-
"--
|
|
313
|
-
],
|
|
314
|
-
"--modifier",
|
|
315
|
-
"g",
|
|
316
|
-
"bar",
|
|
317
|
-
"--globalCommand",
|
|
318
|
-
"bar",
|
|
319
|
-
"--goo",
|
|
320
|
-
"g",
|
|
321
|
-
]],
|
|
213
|
+
[
|
|
214
|
+
["hello", "--world"],
|
|
215
|
+
["--modifier", "g", "bar", "--globalCommand", "bar", "--goo", "g"],
|
|
216
|
+
],
|
|
322
217
|
globalModifierCommandsByName,
|
|
323
218
|
globalModifierCommandsByShortAlias,
|
|
324
219
|
);
|
|
325
220
|
expectScanResult(scanResult, {
|
|
326
|
-
globalModifierCommandClauses: [
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
221
|
+
globalModifierCommandClauses: [
|
|
222
|
+
{
|
|
223
|
+
command: globalModifierCommand,
|
|
224
|
+
potentialArgs: ["g", "bar", "--globalCommand", "bar", "--goo", "g"],
|
|
225
|
+
},
|
|
226
|
+
],
|
|
330
227
|
unusedArgSequences: [["hello", "--world"]],
|
|
331
228
|
});
|
|
332
229
|
});
|
|
333
230
|
|
|
334
231
|
test("Sub-command scanned", () => {
|
|
335
232
|
const subCommand = getSubCommandWithOptionAndPositional();
|
|
336
|
-
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
337
|
-
subCommand.name,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
"--goo",
|
|
344
|
-
"g",
|
|
345
|
-
]], nonModifierCommandsByName);
|
|
233
|
+
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
234
|
+
[subCommand.name, subCommand],
|
|
235
|
+
]);
|
|
236
|
+
let scanResult = scanForNonModifierCommandClause(
|
|
237
|
+
[["subCommand", "bar", "--goo", "g"]],
|
|
238
|
+
nonModifierCommandsByName,
|
|
239
|
+
);
|
|
346
240
|
expectScanResult(scanResult, {
|
|
347
241
|
nonModifierCommandClause: {
|
|
348
242
|
command: subCommand,
|
|
@@ -351,12 +245,10 @@ describe("scanner tests", () => {
|
|
|
351
245
|
unusedArgSequences: [],
|
|
352
246
|
});
|
|
353
247
|
|
|
354
|
-
scanResult = scanForNonModifierCommandClause(
|
|
355
|
-
"subCommand",
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
"g",
|
|
359
|
-
]], nonModifierCommandsByName);
|
|
248
|
+
scanResult = scanForNonModifierCommandClause(
|
|
249
|
+
[[], ["subCommand", "bar", "--goo", "g"]],
|
|
250
|
+
nonModifierCommandsByName,
|
|
251
|
+
);
|
|
360
252
|
|
|
361
253
|
expectScanResult(scanResult, {
|
|
362
254
|
nonModifierCommandClause: {
|
|
@@ -366,12 +258,10 @@ describe("scanner tests", () => {
|
|
|
366
258
|
unusedArgSequences: [],
|
|
367
259
|
});
|
|
368
260
|
|
|
369
|
-
scanResult = scanForNonModifierCommandClause(
|
|
370
|
-
"subCommand",
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
"g",
|
|
374
|
-
]], nonModifierCommandsByName);
|
|
261
|
+
scanResult = scanForNonModifierCommandClause(
|
|
262
|
+
[["subCommand", "bar", "--goo", "g"]],
|
|
263
|
+
nonModifierCommandsByName,
|
|
264
|
+
);
|
|
375
265
|
|
|
376
266
|
expectScanResult(scanResult, {
|
|
377
267
|
nonModifierCommandClause: {
|
|
@@ -384,12 +274,12 @@ describe("scanner tests", () => {
|
|
|
384
274
|
|
|
385
275
|
test("Global command scanned", () => {
|
|
386
276
|
const globalCommand = getGlobalCommandWithShortAlias("globalCommand", "g");
|
|
387
|
-
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
388
|
-
globalCommand.name,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
277
|
+
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
278
|
+
[globalCommand.name, globalCommand],
|
|
279
|
+
]);
|
|
280
|
+
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> = new Map([
|
|
281
|
+
[globalCommand.shortAlias!, globalCommand],
|
|
282
|
+
]);
|
|
393
283
|
|
|
394
284
|
let expected: ScanResult = {
|
|
395
285
|
nonModifierCommandClause: {
|
|
@@ -400,9 +290,7 @@ describe("scanner tests", () => {
|
|
|
400
290
|
};
|
|
401
291
|
|
|
402
292
|
let scanResult = scanForNonModifierCommandClause(
|
|
403
|
-
[
|
|
404
|
-
["--globalCommand", "g", "bar"],
|
|
405
|
-
],
|
|
293
|
+
[["--globalCommand", "g", "bar"]],
|
|
406
294
|
nonModifierCommandsByName,
|
|
407
295
|
globalCommandsByShortAlias,
|
|
408
296
|
);
|
|
@@ -458,10 +346,15 @@ describe("scanner tests", () => {
|
|
|
458
346
|
const groupAndMemberCommandsByJoinedName: ReadonlyMap<
|
|
459
347
|
string,
|
|
460
348
|
{ groupCommand: GroupCommand; command: SubCommand }
|
|
461
|
-
> = new Map([
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
349
|
+
> = new Map([
|
|
350
|
+
[
|
|
351
|
+
`${groupCommand.name}:${subCommand.name}`,
|
|
352
|
+
{
|
|
353
|
+
groupCommand,
|
|
354
|
+
command: subCommand,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
]);
|
|
465
358
|
let expected: ScanResult = {
|
|
466
359
|
nonModifierCommandClause: {
|
|
467
360
|
groupCommand,
|
|
@@ -475,13 +368,7 @@ describe("scanner tests", () => {
|
|
|
475
368
|
]);
|
|
476
369
|
|
|
477
370
|
let scanResult = scanForNonModifierCommandClause(
|
|
478
|
-
[[
|
|
479
|
-
"group",
|
|
480
|
-
"subCommand",
|
|
481
|
-
"bar",
|
|
482
|
-
"--goo",
|
|
483
|
-
"g",
|
|
484
|
-
]],
|
|
371
|
+
[["group", "subCommand", "bar", "--goo", "g"]],
|
|
485
372
|
nonModifierCommandsByName,
|
|
486
373
|
new Map(),
|
|
487
374
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -489,12 +376,7 @@ describe("scanner tests", () => {
|
|
|
489
376
|
expectScanResult(scanResult, expected);
|
|
490
377
|
|
|
491
378
|
scanResult = scanForNonModifierCommandClause(
|
|
492
|
-
[[
|
|
493
|
-
"group:subCommand",
|
|
494
|
-
"bar",
|
|
495
|
-
"--goo",
|
|
496
|
-
"g",
|
|
497
|
-
]],
|
|
379
|
+
[["group:subCommand", "bar", "--goo", "g"]],
|
|
498
380
|
new Map(),
|
|
499
381
|
new Map(),
|
|
500
382
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -511,12 +393,7 @@ describe("scanner tests", () => {
|
|
|
511
393
|
};
|
|
512
394
|
|
|
513
395
|
scanResult = scanForNonModifierCommandClause(
|
|
514
|
-
[[
|
|
515
|
-
"group:subCommand",
|
|
516
|
-
"bar",
|
|
517
|
-
"--goo",
|
|
518
|
-
"g",
|
|
519
|
-
]],
|
|
396
|
+
[["group:subCommand", "bar", "--goo", "g"]],
|
|
520
397
|
new Map(),
|
|
521
398
|
new Map(),
|
|
522
399
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -532,21 +409,12 @@ describe("scanner tests", () => {
|
|
|
532
409
|
[globalCommand.name, globalCommand as Command],
|
|
533
410
|
[subCommand.name, subCommand as Command],
|
|
534
411
|
]);
|
|
535
|
-
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> =
|
|
536
|
-
|
|
412
|
+
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> = new Map([
|
|
413
|
+
[globalCommand.shortAlias!, globalCommand],
|
|
414
|
+
]);
|
|
537
415
|
|
|
538
416
|
let scanResult = scanForNonModifierCommandClause(
|
|
539
|
-
[[
|
|
540
|
-
"hello",
|
|
541
|
-
"--world",
|
|
542
|
-
"subCommand",
|
|
543
|
-
"bar",
|
|
544
|
-
"--goo",
|
|
545
|
-
"g",
|
|
546
|
-
"--modifier",
|
|
547
|
-
"g",
|
|
548
|
-
"bar",
|
|
549
|
-
]],
|
|
417
|
+
[["hello", "--world", "subCommand", "bar", "--goo", "g", "--modifier", "g", "bar"]],
|
|
550
418
|
nonModifierCommandsByName,
|
|
551
419
|
globalCommandsByShortAlias,
|
|
552
420
|
);
|
|
@@ -559,17 +427,7 @@ describe("scanner tests", () => {
|
|
|
559
427
|
});
|
|
560
428
|
|
|
561
429
|
scanResult = scanForNonModifierCommandClause(
|
|
562
|
-
[[
|
|
563
|
-
"hello",
|
|
564
|
-
"--world",
|
|
565
|
-
"--globalCommand",
|
|
566
|
-
"bar",
|
|
567
|
-
"--goo",
|
|
568
|
-
"g",
|
|
569
|
-
"--modifier",
|
|
570
|
-
"g",
|
|
571
|
-
"bar",
|
|
572
|
-
]],
|
|
430
|
+
[["hello", "--world", "--globalCommand", "bar", "--goo", "g", "--modifier", "g", "bar"]],
|
|
573
431
|
nonModifierCommandsByName,
|
|
574
432
|
globalCommandsByShortAlias,
|
|
575
433
|
);
|
|
@@ -581,14 +439,10 @@ describe("scanner tests", () => {
|
|
|
581
439
|
unusedArgSequences: [["hello", "--world"]],
|
|
582
440
|
});
|
|
583
441
|
scanResult = scanForNonModifierCommandClause(
|
|
584
|
-
[
|
|
585
|
-
"hello",
|
|
586
|
-
"--
|
|
587
|
-
|
|
588
|
-
"bar",
|
|
589
|
-
"--goo",
|
|
590
|
-
"g",
|
|
591
|
-
], ["--modifier", "g", "bar"]],
|
|
442
|
+
[
|
|
443
|
+
["hello", "--world", "--globalCommand", "bar", "--goo", "g"],
|
|
444
|
+
["--modifier", "g", "bar"],
|
|
445
|
+
],
|
|
592
446
|
nonModifierCommandsByName,
|
|
593
447
|
globalCommandsByShortAlias,
|
|
594
448
|
);
|
|
@@ -597,7 +451,10 @@ describe("scanner tests", () => {
|
|
|
597
451
|
command: globalCommand,
|
|
598
452
|
potentialArgs: ["bar", "--goo", "g"],
|
|
599
453
|
},
|
|
600
|
-
unusedArgSequences: [
|
|
454
|
+
unusedArgSequences: [
|
|
455
|
+
["hello", "--world"],
|
|
456
|
+
["--modifier", "g", "bar"],
|
|
457
|
+
],
|
|
601
458
|
});
|
|
602
459
|
});
|
|
603
460
|
|
|
@@ -608,16 +465,21 @@ describe("scanner tests", () => {
|
|
|
608
465
|
[subCommand.name, subCommand],
|
|
609
466
|
]);
|
|
610
467
|
|
|
611
|
-
let scanResult = scanForNonModifierCommandClause(
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
468
|
+
let scanResult = scanForNonModifierCommandClause(
|
|
469
|
+
[
|
|
470
|
+
[
|
|
471
|
+
"subCommand",
|
|
472
|
+
"-a.b.g=foo1",
|
|
473
|
+
"-a.b.d=1",
|
|
474
|
+
"-a.b.g=foo2",
|
|
475
|
+
"-a.b.d=2",
|
|
476
|
+
"-a.b.d=3",
|
|
477
|
+
"-e.g=bar",
|
|
478
|
+
"-e.d=1",
|
|
479
|
+
],
|
|
480
|
+
],
|
|
481
|
+
nonModifierCommandsByName,
|
|
482
|
+
);
|
|
621
483
|
expectScanResult(scanResult, {
|
|
622
484
|
nonModifierCommandClause: {
|
|
623
485
|
command: subCommand,
|
|
@@ -633,16 +495,21 @@ describe("scanner tests", () => {
|
|
|
633
495
|
},
|
|
634
496
|
unusedArgSequences: [],
|
|
635
497
|
});
|
|
636
|
-
scanResult = scanForNonModifierCommandClause(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
498
|
+
scanResult = scanForNonModifierCommandClause(
|
|
499
|
+
[
|
|
500
|
+
[
|
|
501
|
+
"subCommand",
|
|
502
|
+
"--alpha.beta.gamma=foo1",
|
|
503
|
+
"-a.b.d=1",
|
|
504
|
+
"-a.b.g=foo2",
|
|
505
|
+
"-a.b.d=2",
|
|
506
|
+
"-a.b.d=3",
|
|
507
|
+
"-e.g=bar",
|
|
508
|
+
"-e.d=1",
|
|
509
|
+
],
|
|
510
|
+
],
|
|
511
|
+
nonModifierCommandsByName,
|
|
512
|
+
);
|
|
646
513
|
expectScanResult(scanResult, {
|
|
647
514
|
nonModifierCommandClause: {
|
|
648
515
|
command: subCommand,
|
|
@@ -658,16 +525,21 @@ describe("scanner tests", () => {
|
|
|
658
525
|
},
|
|
659
526
|
unusedArgSequences: [],
|
|
660
527
|
});
|
|
661
|
-
scanResult = scanForNonModifierCommandClause(
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
528
|
+
scanResult = scanForNonModifierCommandClause(
|
|
529
|
+
[
|
|
530
|
+
[
|
|
531
|
+
"subCommand",
|
|
532
|
+
"-e.g=bar",
|
|
533
|
+
"-e.d=1",
|
|
534
|
+
"-a.b[1].g=foo2",
|
|
535
|
+
"--alpha.beta[0].gamma=foo1",
|
|
536
|
+
"-a.b[1].d[1]=2",
|
|
537
|
+
"-a.b[0].d=1",
|
|
538
|
+
"-a.b[1].d[0]=3",
|
|
539
|
+
],
|
|
540
|
+
],
|
|
541
|
+
nonModifierCommandsByName,
|
|
542
|
+
);
|
|
671
543
|
expectScanResult(scanResult, {
|
|
672
544
|
nonModifierCommandClause: {
|
|
673
545
|
command: subCommand,
|
|
@@ -691,21 +563,21 @@ describe("scanner tests", () => {
|
|
|
691
563
|
const groupAndMemberCommandsByJoinedName: ReadonlyMap<
|
|
692
564
|
string,
|
|
693
565
|
{ groupCommand: GroupCommand; command: SubCommand }
|
|
694
|
-
> = new Map([
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
566
|
+
> = new Map([
|
|
567
|
+
[
|
|
568
|
+
`${groupCommand.name}:${subCommand.name}`,
|
|
569
|
+
{
|
|
570
|
+
groupCommand,
|
|
571
|
+
command: subCommand,
|
|
572
|
+
},
|
|
573
|
+
],
|
|
574
|
+
]);
|
|
698
575
|
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
699
576
|
[groupCommand.name, groupCommand],
|
|
700
577
|
]);
|
|
701
578
|
|
|
702
579
|
const scanResult = scanForNonModifierCommandClause(
|
|
703
|
-
[[
|
|
704
|
-
"subCommand",
|
|
705
|
-
"foo",
|
|
706
|
-
"--goo",
|
|
707
|
-
"g",
|
|
708
|
-
]],
|
|
580
|
+
[["subCommand", "foo", "--goo", "g"]],
|
|
709
581
|
nonModifierCommandsByName,
|
|
710
582
|
new Map(),
|
|
711
583
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -721,8 +593,9 @@ describe("scanner tests", () => {
|
|
|
721
593
|
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
722
594
|
[globalCommand.name, globalCommand],
|
|
723
595
|
]);
|
|
724
|
-
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> =
|
|
725
|
-
|
|
596
|
+
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> = new Map([
|
|
597
|
+
[globalCommand.shortAlias!, globalCommand],
|
|
598
|
+
]);
|
|
726
599
|
|
|
727
600
|
const expected: ScanResult = {
|
|
728
601
|
nonModifierCommandClause: {
|
|
@@ -733,42 +606,28 @@ describe("scanner tests", () => {
|
|
|
733
606
|
};
|
|
734
607
|
|
|
735
608
|
let scanResult = scanForNonModifierCommandClause(
|
|
736
|
-
[[
|
|
737
|
-
"--globalCommand",
|
|
738
|
-
"g=2",
|
|
739
|
-
"bar=2",
|
|
740
|
-
]],
|
|
609
|
+
[["--globalCommand", "g=2", "bar=2"]],
|
|
741
610
|
nonModifierCommandsByName,
|
|
742
611
|
globalCommandsByShortAlias,
|
|
743
612
|
);
|
|
744
613
|
expectScanResult(scanResult, expected);
|
|
745
614
|
|
|
746
615
|
scanResult = scanForNonModifierCommandClause(
|
|
747
|
-
[[
|
|
748
|
-
"--globalCommand=g=2",
|
|
749
|
-
"bar=2",
|
|
750
|
-
]],
|
|
616
|
+
[["--globalCommand=g=2", "bar=2"]],
|
|
751
617
|
nonModifierCommandsByName,
|
|
752
618
|
globalCommandsByShortAlias,
|
|
753
619
|
);
|
|
754
620
|
expectScanResult(scanResult, expected);
|
|
755
621
|
|
|
756
622
|
scanResult = scanForNonModifierCommandClause(
|
|
757
|
-
[[
|
|
758
|
-
"-g",
|
|
759
|
-
"g=2",
|
|
760
|
-
"bar=2",
|
|
761
|
-
]],
|
|
623
|
+
[["-g", "g=2", "bar=2"]],
|
|
762
624
|
nonModifierCommandsByName,
|
|
763
625
|
globalCommandsByShortAlias,
|
|
764
626
|
);
|
|
765
627
|
expectScanResult(scanResult, expected);
|
|
766
628
|
|
|
767
629
|
scanResult = scanForNonModifierCommandClause(
|
|
768
|
-
[[
|
|
769
|
-
"-g=g=2",
|
|
770
|
-
"bar=2",
|
|
771
|
-
]],
|
|
630
|
+
[["-g=g=2", "bar=2"]],
|
|
772
631
|
nonModifierCommandsByName,
|
|
773
632
|
globalCommandsByShortAlias,
|
|
774
633
|
);
|
|
@@ -781,8 +640,9 @@ describe("scanner tests", () => {
|
|
|
781
640
|
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
782
641
|
[globalCommand.name, globalCommand],
|
|
783
642
|
]);
|
|
784
|
-
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> =
|
|
785
|
-
|
|
643
|
+
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> = new Map([
|
|
644
|
+
[globalCommand.shortAlias!, globalCommand],
|
|
645
|
+
]);
|
|
786
646
|
|
|
787
647
|
const expected: ScanResult = {
|
|
788
648
|
nonModifierCommandClause: {
|
|
@@ -793,10 +653,7 @@ describe("scanner tests", () => {
|
|
|
793
653
|
};
|
|
794
654
|
|
|
795
655
|
const scanResult = scanForNonModifierCommandClause(
|
|
796
|
-
[[
|
|
797
|
-
"--globalCommand",
|
|
798
|
-
"g=",
|
|
799
|
-
]],
|
|
656
|
+
[["--globalCommand", "g="]],
|
|
800
657
|
nonModifierCommandsByName,
|
|
801
658
|
globalCommandsByShortAlias,
|
|
802
659
|
);
|
|
@@ -809,14 +666,10 @@ describe("scanner tests", () => {
|
|
|
809
666
|
[subCommand.name, subCommand],
|
|
810
667
|
]);
|
|
811
668
|
|
|
812
|
-
const scanResult = scanForNonModifierCommandClause(
|
|
813
|
-
"subCommand",
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
"g",
|
|
817
|
-
"subCommand",
|
|
818
|
-
"bar",
|
|
819
|
-
]], nonModifierCommandsByName);
|
|
669
|
+
const scanResult = scanForNonModifierCommandClause(
|
|
670
|
+
[["subCommand", "bar", "--goo", "g", "subCommand", "bar"]],
|
|
671
|
+
nonModifierCommandsByName,
|
|
672
|
+
);
|
|
820
673
|
expectScanResult(scanResult, {
|
|
821
674
|
nonModifierCommandClause: {
|
|
822
675
|
command: subCommand,
|
|
@@ -832,22 +685,21 @@ describe("scanner tests", () => {
|
|
|
832
685
|
const groupAndMemberCommandsByJoinedName: ReadonlyMap<
|
|
833
686
|
string,
|
|
834
687
|
{ groupCommand: GroupCommand; command: SubCommand }
|
|
835
|
-
> = new Map([
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
688
|
+
> = new Map([
|
|
689
|
+
[
|
|
690
|
+
`${groupCommand.name}:${subCommand.name}`,
|
|
691
|
+
{
|
|
692
|
+
groupCommand,
|
|
693
|
+
command: subCommand,
|
|
694
|
+
},
|
|
695
|
+
],
|
|
696
|
+
]);
|
|
839
697
|
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
840
698
|
[groupCommand.name, groupCommand],
|
|
841
699
|
]);
|
|
842
700
|
|
|
843
701
|
let scanResult = scanForNonModifierCommandClause(
|
|
844
|
-
[[
|
|
845
|
-
"group",
|
|
846
|
-
"blah",
|
|
847
|
-
"bar",
|
|
848
|
-
"--goo",
|
|
849
|
-
"g",
|
|
850
|
-
]],
|
|
702
|
+
[["group", "blah", "bar", "--goo", "g"]],
|
|
851
703
|
nonModifierCommandsByName,
|
|
852
704
|
new Map(),
|
|
853
705
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -857,12 +709,7 @@ describe("scanner tests", () => {
|
|
|
857
709
|
});
|
|
858
710
|
|
|
859
711
|
scanResult = scanForNonModifierCommandClause(
|
|
860
|
-
[[
|
|
861
|
-
"group:blah",
|
|
862
|
-
"bar",
|
|
863
|
-
"--goo",
|
|
864
|
-
"g",
|
|
865
|
-
]],
|
|
712
|
+
[["group:blah", "bar", "--goo", "g"]],
|
|
866
713
|
nonModifierCommandsByName,
|
|
867
714
|
new Map(),
|
|
868
715
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -880,14 +727,20 @@ describe("scanner tests", () => {
|
|
|
880
727
|
string,
|
|
881
728
|
{ groupCommand: GroupCommand; command: SubCommand }
|
|
882
729
|
> = new Map([
|
|
883
|
-
[
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
730
|
+
[
|
|
731
|
+
`${groupCommand1.name}:${subCommand.name}`,
|
|
732
|
+
{
|
|
733
|
+
groupCommand: groupCommand1,
|
|
734
|
+
command: subCommand,
|
|
735
|
+
},
|
|
736
|
+
],
|
|
737
|
+
[
|
|
738
|
+
`${groupCommand2.name}:${subCommand.name}`,
|
|
739
|
+
{
|
|
740
|
+
groupCommand: groupCommand2,
|
|
741
|
+
command: subCommand,
|
|
742
|
+
},
|
|
743
|
+
],
|
|
891
744
|
]);
|
|
892
745
|
const nonModifierCommandsByName: ReadonlyMap<string, Command> = new Map([
|
|
893
746
|
[groupCommand1.name, groupCommand1],
|
|
@@ -895,18 +748,7 @@ describe("scanner tests", () => {
|
|
|
895
748
|
]);
|
|
896
749
|
|
|
897
750
|
let scanResult = scanForNonModifierCommandClause(
|
|
898
|
-
[[
|
|
899
|
-
"group1",
|
|
900
|
-
"subCommand",
|
|
901
|
-
"bar",
|
|
902
|
-
"--goo",
|
|
903
|
-
"g",
|
|
904
|
-
"group2",
|
|
905
|
-
"subCommand",
|
|
906
|
-
"bar",
|
|
907
|
-
"--goo",
|
|
908
|
-
"g",
|
|
909
|
-
]],
|
|
751
|
+
[["group1", "subCommand", "bar", "--goo", "g", "group2", "subCommand", "bar", "--goo", "g"]],
|
|
910
752
|
nonModifierCommandsByName,
|
|
911
753
|
new Map(),
|
|
912
754
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -915,32 +757,13 @@ describe("scanner tests", () => {
|
|
|
915
757
|
nonModifierCommandClause: {
|
|
916
758
|
groupCommand: groupCommand1,
|
|
917
759
|
command: subCommand,
|
|
918
|
-
potentialArgs: [
|
|
919
|
-
"bar",
|
|
920
|
-
"--goo",
|
|
921
|
-
"g",
|
|
922
|
-
"group2",
|
|
923
|
-
"subCommand",
|
|
924
|
-
"bar",
|
|
925
|
-
"--goo",
|
|
926
|
-
"g",
|
|
927
|
-
],
|
|
760
|
+
potentialArgs: ["bar", "--goo", "g", "group2", "subCommand", "bar", "--goo", "g"],
|
|
928
761
|
},
|
|
929
762
|
unusedArgSequences: [],
|
|
930
763
|
});
|
|
931
764
|
|
|
932
765
|
scanResult = scanForNonModifierCommandClause(
|
|
933
|
-
[[
|
|
934
|
-
"group1",
|
|
935
|
-
"subCommand",
|
|
936
|
-
"bar",
|
|
937
|
-
"--goo",
|
|
938
|
-
"g",
|
|
939
|
-
"group2:command",
|
|
940
|
-
"bar",
|
|
941
|
-
"--goo",
|
|
942
|
-
"g",
|
|
943
|
-
]],
|
|
766
|
+
[["group1", "subCommand", "bar", "--goo", "g", "group2:command", "bar", "--goo", "g"]],
|
|
944
767
|
new Map(),
|
|
945
768
|
new Map(),
|
|
946
769
|
groupAndMemberCommandsByJoinedName,
|
|
@@ -949,15 +772,7 @@ describe("scanner tests", () => {
|
|
|
949
772
|
nonModifierCommandClause: {
|
|
950
773
|
groupCommand: groupCommand1,
|
|
951
774
|
command: subCommand,
|
|
952
|
-
potentialArgs: [
|
|
953
|
-
"bar",
|
|
954
|
-
"--goo",
|
|
955
|
-
"g",
|
|
956
|
-
"group2:command",
|
|
957
|
-
"bar",
|
|
958
|
-
"--goo",
|
|
959
|
-
"g",
|
|
960
|
-
],
|
|
775
|
+
potentialArgs: ["bar", "--goo", "g", "group2:command", "bar", "--goo", "g"],
|
|
961
776
|
},
|
|
962
777
|
unusedArgSequences: [],
|
|
963
778
|
});
|
|
@@ -970,26 +785,29 @@ describe("scanner tests", () => {
|
|
|
970
785
|
[subCommand.name, subCommand as Command],
|
|
971
786
|
[globalCommand.name, globalCommand as Command],
|
|
972
787
|
]);
|
|
973
|
-
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> =
|
|
974
|
-
|
|
788
|
+
const globalCommandsByShortAlias: ReadonlyMap<string, GlobalCommand> = new Map([
|
|
789
|
+
[globalCommand.shortAlias!, globalCommand],
|
|
790
|
+
]);
|
|
975
791
|
|
|
976
792
|
let scanResult = scanForNonModifierCommandClause(
|
|
977
|
-
[
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
793
|
+
[
|
|
794
|
+
[
|
|
795
|
+
"subCommand",
|
|
796
|
+
"bar",
|
|
797
|
+
"--goo",
|
|
798
|
+
"g",
|
|
799
|
+
"--modifier1",
|
|
800
|
+
"g",
|
|
801
|
+
"bar",
|
|
802
|
+
"--globalCommand",
|
|
803
|
+
"bar",
|
|
804
|
+
"--goo",
|
|
805
|
+
"g",
|
|
806
|
+
"--modifier2",
|
|
807
|
+
"g",
|
|
808
|
+
"bar",
|
|
809
|
+
],
|
|
810
|
+
],
|
|
993
811
|
nonModifierCommandsByName,
|
|
994
812
|
globalCommandsByShortAlias,
|
|
995
813
|
);
|
|
@@ -1016,35 +834,14 @@ describe("scanner tests", () => {
|
|
|
1016
834
|
});
|
|
1017
835
|
|
|
1018
836
|
scanResult = scanForNonModifierCommandClause(
|
|
1019
|
-
[[
|
|
1020
|
-
"subCommand",
|
|
1021
|
-
"bar",
|
|
1022
|
-
"--goo=g",
|
|
1023
|
-
"-1=g",
|
|
1024
|
-
"bar",
|
|
1025
|
-
"-g=bar",
|
|
1026
|
-
"--goo",
|
|
1027
|
-
"g",
|
|
1028
|
-
"-2=g",
|
|
1029
|
-
"bar",
|
|
1030
|
-
]],
|
|
837
|
+
[["subCommand", "bar", "--goo=g", "-1=g", "bar", "-g=bar", "--goo", "g", "-2=g", "bar"]],
|
|
1031
838
|
nonModifierCommandsByName,
|
|
1032
839
|
globalCommandsByShortAlias,
|
|
1033
840
|
);
|
|
1034
841
|
expectScanResult(scanResult, {
|
|
1035
842
|
nonModifierCommandClause: {
|
|
1036
843
|
command: subCommand,
|
|
1037
|
-
potentialArgs: [
|
|
1038
|
-
"bar",
|
|
1039
|
-
"--goo=g",
|
|
1040
|
-
"-1=g",
|
|
1041
|
-
"bar",
|
|
1042
|
-
"-g=bar",
|
|
1043
|
-
"--goo",
|
|
1044
|
-
"g",
|
|
1045
|
-
"-2=g",
|
|
1046
|
-
"bar",
|
|
1047
|
-
],
|
|
844
|
+
potentialArgs: ["bar", "--goo=g", "-1=g", "bar", "-g=bar", "--goo", "g", "-2=g", "bar"],
|
|
1048
845
|
},
|
|
1049
846
|
unusedArgSequences: [],
|
|
1050
847
|
});
|
|
@@ -1061,29 +858,34 @@ describe("scanner tests", () => {
|
|
|
1061
858
|
string,
|
|
1062
859
|
{ groupCommand: GroupCommand; command: SubCommand }
|
|
1063
860
|
> = new Map([
|
|
1064
|
-
[
|
|
1065
|
-
groupCommand
|
|
1066
|
-
|
|
1067
|
-
|
|
861
|
+
[
|
|
862
|
+
`${groupCommand.name}:${subCommand.name}`,
|
|
863
|
+
{
|
|
864
|
+
groupCommand,
|
|
865
|
+
command: subCommand,
|
|
866
|
+
},
|
|
867
|
+
],
|
|
1068
868
|
]);
|
|
1069
869
|
|
|
1070
870
|
const scanResult = scanForNonModifierCommandClause(
|
|
1071
|
-
[
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
871
|
+
[
|
|
872
|
+
[
|
|
873
|
+
"subCommand",
|
|
874
|
+
"bar",
|
|
875
|
+
"--goo",
|
|
876
|
+
"g",
|
|
877
|
+
"--modifier1",
|
|
878
|
+
"g",
|
|
879
|
+
"bar",
|
|
880
|
+
"group:command",
|
|
881
|
+
"bar",
|
|
882
|
+
"--goo",
|
|
883
|
+
"g",
|
|
884
|
+
"--modifier2",
|
|
885
|
+
"g",
|
|
886
|
+
"bar",
|
|
887
|
+
],
|
|
888
|
+
],
|
|
1087
889
|
nonModifierCommandsByName,
|
|
1088
890
|
new Map(),
|
|
1089
891
|
groupAndMemberCommandsByJoinedName,
|