@@ -22,7 +22,7 @@ describe("utils", function () {
22
22
id : [ "task" ] ,
23
23
description : "task description" ,
24
24
actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
25
- namedParameters : new Map ( ) ,
25
+ options : new Map ( ) ,
26
26
positionalParameters : [ ] ,
27
27
pluginId : "task-plugin-id" ,
28
28
subtasks : new Map ( ) . set ( "subtask" , {
@@ -53,7 +53,7 @@ describe("utils", function () {
53
53
id : [ "task" ] ,
54
54
description : "task description" ,
55
55
actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
56
- namedParameters : new Map ( ) ,
56
+ options : new Map ( ) ,
57
57
positionalParameters : [ ] ,
58
58
pluginId : "task-plugin-id" ,
59
59
subtasks : new Map ( ) . set ( "subtask" , {
@@ -86,7 +86,7 @@ describe("utils", function () {
86
86
id : [ "task" ] ,
87
87
description : "task description" ,
88
88
actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
89
- namedParameters : new Map ( ) ,
89
+ options : new Map ( ) ,
90
90
positionalParameters : [ ] ,
91
91
pluginId : "task-plugin-id" ,
92
92
subtasks : new Map ( ) . set ( "subtask" , {
@@ -116,7 +116,7 @@ describe("utils", function () {
116
116
id : [ "task" ] ,
117
117
description : "task description" ,
118
118
actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
119
- namedParameters : new Map ( )
119
+ options : new Map ( )
120
120
. set ( "option" , {
121
121
name : "option" ,
122
122
description : "An example option" ,
@@ -134,6 +134,13 @@ describe("utils", function () {
134
134
parameterType : ParameterType . STRING ,
135
135
isVariadic : false ,
136
136
} ,
137
+ {
138
+ name : "anotherPositionalArgument" ,
139
+ description : "Another example argument" ,
140
+ parameterType : ParameterType . STRING ,
141
+ isVariadic : false ,
142
+ defaultValue : "default" ,
143
+ } ,
137
144
] ,
138
145
pluginId : "task-plugin-id" ,
139
146
subtasks : new Map ( ) ,
@@ -160,6 +167,12 @@ describe("utils", function () {
160
167
{
161
168
name : "positionalArgument" ,
162
169
description : "An example argument" ,
170
+ isRequired : true ,
171
+ } ,
172
+ {
173
+ name : "anotherPositionalArgument" ,
174
+ description : "Another example argument" ,
175
+ isRequired : false ,
163
176
} ,
164
177
] ,
165
178
} ) ;
@@ -207,56 +220,124 @@ Section Title:
207
220
} ) ;
208
221
209
222
describe ( "getUsageString" , function ( ) {
210
- it ( "should return a usage string" , function ( ) {
211
- const task : Task = {
212
- id : [ "task" ] ,
213
- description : "task description" ,
214
- actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
215
- namedParameters : new Map ( )
216
- . set ( "option" , {
217
- name : "option" ,
218
- description : "An example option" ,
219
- parameterType : ParameterType . STRING ,
220
- } )
221
- . set ( "anotherOption" , {
222
- name : "anotherOption" ,
223
- description : "Another example option" ,
224
- parameterType : ParameterType . BOOLEAN ,
225
- } ) ,
226
- positionalParameters : [
227
- {
228
- name : "positionalArgument" ,
229
- description : "An example argument" ,
230
- parameterType : ParameterType . STRING ,
231
- isVariadic : false ,
232
- } ,
233
- ] ,
234
- pluginId : "task-plugin-id" ,
235
- subtasks : new Map ( ) ,
236
- isEmpty : false ,
237
- run : async ( ) => { } ,
238
- } ;
223
+ describe ( "with a required positional parameter" , function ( ) {
224
+ it ( "should return a usage string" , function ( ) {
225
+ const task : Task = {
226
+ id : [ "task" ] ,
227
+ description : "task description" ,
228
+ actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
229
+ options : new Map ( )
230
+ . set ( "option" , {
231
+ name : "option" ,
232
+ description : "An example option" ,
233
+ parameterType : ParameterType . STRING ,
234
+ } )
235
+ . set ( "anotherOption" , {
236
+ name : "anotherOption" ,
237
+ description : "Another example option" ,
238
+ parameterType : ParameterType . BOOLEAN ,
239
+ } ) ,
240
+ positionalParameters : [
241
+ {
242
+ name : "positionalArgument" ,
243
+ description : "An example argument" ,
244
+ parameterType : ParameterType . STRING ,
245
+ isVariadic : false ,
246
+ } ,
247
+ ] ,
248
+ pluginId : "task-plugin-id" ,
249
+ subtasks : new Map ( ) ,
250
+ isEmpty : false ,
251
+ run : async ( ) => { } ,
252
+ } ;
239
253
240
- const usageString = getUsageString (
241
- task ,
242
- [
243
- {
244
- name : "--option" ,
245
- description : "An example option" ,
246
- type : ParameterType . STRING ,
247
- } ,
248
- {
249
- name : "--another-option" ,
250
- description : "Another example option" ,
251
- type : ParameterType . BOOLEAN ,
252
- } ,
253
- ] ,
254
- [ { name : "positionalArgument" , description : "An example argument" } ] ,
255
- ) ;
254
+ const usageString = getUsageString (
255
+ task ,
256
+ [
257
+ {
258
+ name : "--option" ,
259
+ description : "An example option" ,
260
+ type : ParameterType . STRING ,
261
+ } ,
262
+ {
263
+ name : "--another-option" ,
264
+ description : "Another example option" ,
265
+ type : ParameterType . BOOLEAN ,
266
+ } ,
267
+ ] ,
268
+ [
269
+ {
270
+ name : "positionalArgument" ,
271
+ description : "An example argument" ,
272
+ isRequired : true ,
273
+ } ,
274
+ ] ,
275
+ ) ;
256
276
257
- const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] positionalArgument` ;
277
+ const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] positionalArgument` ;
278
+
279
+ assert . equal ( usageString , expected ) ;
280
+ } ) ;
281
+ } ) ;
258
282
259
- assert . equal ( usageString , expected ) ;
283
+ describe ( "with an optional positional parameter" , function ( ) {
284
+ it ( "should return a usage string" , function ( ) {
285
+ const task : Task = {
286
+ id : [ "task" ] ,
287
+ description : "task description" ,
288
+ actions : [ { pluginId : "task-plugin-id" , action : ( ) => { } } ] ,
289
+ options : new Map ( )
290
+ . set ( "option" , {
291
+ name : "option" ,
292
+ description : "An example option" ,
293
+ parameterType : ParameterType . STRING ,
294
+ } )
295
+ . set ( "anotherOption" , {
296
+ name : "anotherOption" ,
297
+ description : "Another example option" ,
298
+ parameterType : ParameterType . BOOLEAN ,
299
+ } ) ,
300
+ positionalParameters : [
301
+ {
302
+ name : "positionalArgument" ,
303
+ description : "An example argument" ,
304
+ parameterType : ParameterType . STRING ,
305
+ isVariadic : false ,
306
+ } ,
307
+ ] ,
308
+ pluginId : "task-plugin-id" ,
309
+ subtasks : new Map ( ) ,
310
+ isEmpty : false ,
311
+ run : async ( ) => { } ,
312
+ } ;
313
+
314
+ const usageString = getUsageString (
315
+ task ,
316
+ [
317
+ {
318
+ name : "--option" ,
319
+ description : "An example option" ,
320
+ type : ParameterType . STRING ,
321
+ } ,
322
+ {
323
+ name : "--another-option" ,
324
+ description : "Another example option" ,
325
+ type : ParameterType . BOOLEAN ,
326
+ } ,
327
+ ] ,
328
+ [
329
+ {
330
+ name : "positionalArgument" ,
331
+ description : "An example argument" ,
332
+ isRequired : false ,
333
+ } ,
334
+ ] ,
335
+ ) ;
336
+
337
+ const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] [positionalArgument]` ;
338
+
339
+ assert . equal ( usageString , expected ) ;
340
+ } ) ;
260
341
} ) ;
261
342
} ) ;
262
343
} ) ;
0 commit comments