@flowscripter/dynamic-cli-framework 1.2.2 → 1.3.1

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