1
- import type { ArgumentValue } from "@ignored/hardhat-vnext-core/types/arguments" ;
2
1
import type {
3
2
GlobalOptions ,
4
3
GlobalOptionDefinition ,
@@ -16,6 +15,7 @@ import "tsx"; // NOTE: This is important, it allows us to load .ts files form th
16
15
17
16
import {
18
17
buildGlobalOptionDefinitions ,
18
+ parseArgumentValue ,
19
19
resolvePluginList ,
20
20
} from "@ignored/hardhat-vnext-core" ;
21
21
import { ArgumentType } from "@ignored/hardhat-vnext-core/types/arguments" ;
@@ -521,110 +521,3 @@ function validateRequiredArguments(
521
521
{ argument : missingRequiredArgument . name } ,
522
522
) ;
523
523
}
524
-
525
- function parseArgumentValue (
526
- strValue : string ,
527
- type : ArgumentType ,
528
- argName : string ,
529
- ) : ArgumentValue {
530
- switch ( type ) {
531
- case ArgumentType . STRING :
532
- return validateAndParseString ( argName , strValue ) ;
533
- case ArgumentType . FILE :
534
- return validateAndParseFile ( argName , strValue ) ;
535
- case ArgumentType . INT :
536
- return validateAndParseInt ( argName , strValue ) ;
537
- case ArgumentType . FLOAT :
538
- return validateAndParseFloat ( argName , strValue ) ;
539
- case ArgumentType . BIGINT :
540
- return validateAndParseBigInt ( argName , strValue ) ;
541
- case ArgumentType . BOOLEAN :
542
- return validateAndParseBoolean ( argName , strValue ) ;
543
- }
544
- }
545
-
546
- function validateAndParseInt ( argName : string , strValue : string ) : number {
547
- const decimalPattern = / ^ \d + (?: [ e E ] \d + ) ? $ / ;
548
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
549
-
550
- if (
551
- strValue . match ( decimalPattern ) === null &&
552
- strValue . match ( hexPattern ) === null
553
- ) {
554
- throw new HardhatError (
555
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
556
- {
557
- value : strValue ,
558
- name : argName ,
559
- type : "int" ,
560
- } ,
561
- ) ;
562
- }
563
-
564
- return Number ( strValue ) ;
565
- }
566
-
567
- function validateAndParseString ( _argName : string , strValue : string ) : string {
568
- return strValue ;
569
- }
570
-
571
- function validateAndParseFile ( _argName : string , strValue : string ) : string {
572
- return strValue ;
573
- }
574
-
575
- function validateAndParseFloat ( argName : string , strValue : string ) : number {
576
- const decimalPattern = / ^ (?: \d + (?: \. \d * ) ? | \. \d + ) (?: [ e E ] \d + ) ? $ / ;
577
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
578
-
579
- if (
580
- strValue . match ( decimalPattern ) === null &&
581
- strValue . match ( hexPattern ) === null
582
- ) {
583
- throw new HardhatError (
584
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
585
- {
586
- value : strValue ,
587
- name : argName ,
588
- type : "float" ,
589
- } ,
590
- ) ;
591
- }
592
-
593
- return Number ( strValue ) ;
594
- }
595
-
596
- function validateAndParseBigInt ( argName : string , strValue : string ) : bigint {
597
- const decimalPattern = / ^ \d + (?: n ) ? $ / ;
598
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
599
-
600
- if (
601
- strValue . match ( decimalPattern ) === null &&
602
- strValue . match ( hexPattern ) === null
603
- ) {
604
- throw new HardhatError (
605
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
606
- {
607
- value : strValue ,
608
- name : argName ,
609
- type : "bigint" ,
610
- } ,
611
- ) ;
612
- }
613
-
614
- return BigInt ( strValue . replace ( "n" , "" ) ) ;
615
- }
616
-
617
- function validateAndParseBoolean ( argName : string , strValue : string ) : boolean {
618
- if ( strValue . toLowerCase ( ) === "true" ) {
619
- return true ;
620
- }
621
- if ( strValue . toLowerCase ( ) === "false" ) {
622
- return false ;
623
- }
624
-
625
- throw new HardhatError ( HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE , {
626
- value : strValue ,
627
- name : argName ,
628
- type : "boolean" ,
629
- } ) ;
630
- }
0 commit comments