File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ export async function parseGlobalArguments(
224
224
usedCliArguments ,
225
225
parameters ,
226
226
globalArguments ,
227
+ true ,
227
228
) ;
228
229
229
230
return globalArguments ;
@@ -357,6 +358,7 @@ function parseDoubleDashArgs(
357
358
usedCliArguments : boolean [ ] ,
358
359
parametersMap : Map < string , NamedTaskParameter | GlobalParameter > ,
359
360
argumentsMap : TaskArguments ,
361
+ ignoreUnknownParameter = false ,
360
362
) {
361
363
for ( let i = 0 ; i < cliArguments . length ; i ++ ) {
362
364
if ( usedCliArguments [ i ] ) {
@@ -379,6 +381,11 @@ function parseDoubleDashArgs(
379
381
const paramInfo = parametersMap . get ( paramName ) ;
380
382
381
383
if ( paramInfo === undefined ) {
384
+ if ( ignoreUnknownParameter === true ) {
385
+ continue ;
386
+ }
387
+
388
+ // Only throw an error when the parameter is not a global parameter, because it might be a parameter related to a task
382
389
throw new HardhatError (
383
390
HardhatError . ERRORS . ARGUMENTS . UNRECOGNIZED_NAMED_PARAM ,
384
391
{
Original file line number Diff line number Diff line change @@ -214,6 +214,22 @@ describe("main", function () {
214
214
flag : true ,
215
215
} ) ;
216
216
} ) ;
217
+
218
+ it ( "should not fail when a global parameter is not recognized (it might be a task parameter)" , async function ( ) {
219
+ const command = "npx hardhat task --taskFlag <value>" ;
220
+
221
+ const cliArguments = command . split ( " " ) . slice ( 2 ) ;
222
+ const usedCliArguments = new Array ( cliArguments . length ) . fill ( false ) ;
223
+
224
+ const globalArguments = await parseGlobalArguments (
225
+ globalParamsIndex ,
226
+ cliArguments ,
227
+ usedCliArguments ,
228
+ ) ;
229
+
230
+ assert . deepEqual ( usedCliArguments , [ false , false , false ] ) ;
231
+ assert . deepEqual ( globalArguments , { } ) ;
232
+ } ) ;
217
233
} ) ;
218
234
219
235
describe ( "parseTaskAndArguments" , function ( ) {
You can’t perform that action at this time.
0 commit comments