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" ;
@@ -516,110 +516,3 @@ function validateRequiredArguments(
516
516
{ argument : missingRequiredArgument . name } ,
517
517
) ;
518
518
}
519
-
520
- function parseArgumentValue (
521
- strValue : string ,
522
- type : ArgumentType ,
523
- argName : string ,
524
- ) : ArgumentValue {
525
- switch ( type ) {
526
- case ArgumentType . STRING :
527
- return validateAndParseString ( argName , strValue ) ;
528
- case ArgumentType . FILE :
529
- return validateAndParseFile ( argName , strValue ) ;
530
- case ArgumentType . INT :
531
- return validateAndParseInt ( argName , strValue ) ;
532
- case ArgumentType . FLOAT :
533
- return validateAndParseFloat ( argName , strValue ) ;
534
- case ArgumentType . BIGINT :
535
- return validateAndParseBigInt ( argName , strValue ) ;
536
- case ArgumentType . BOOLEAN :
537
- return validateAndParseBoolean ( argName , strValue ) ;
538
- }
539
- }
540
-
541
- function validateAndParseInt ( argName : string , strValue : string ) : number {
542
- const decimalPattern = / ^ \d + (?: [ e E ] \d + ) ? $ / ;
543
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
544
-
545
- if (
546
- strValue . match ( decimalPattern ) === null &&
547
- strValue . match ( hexPattern ) === null
548
- ) {
549
- throw new HardhatError (
550
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
551
- {
552
- value : strValue ,
553
- name : argName ,
554
- type : "int" ,
555
- } ,
556
- ) ;
557
- }
558
-
559
- return Number ( strValue ) ;
560
- }
561
-
562
- function validateAndParseString ( _argName : string , strValue : string ) : string {
563
- return strValue ;
564
- }
565
-
566
- function validateAndParseFile ( _argName : string , strValue : string ) : string {
567
- return strValue ;
568
- }
569
-
570
- function validateAndParseFloat ( argName : string , strValue : string ) : number {
571
- const decimalPattern = / ^ (?: \d + (?: \. \d * ) ? | \. \d + ) (?: [ e E ] \d + ) ? $ / ;
572
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
573
-
574
- if (
575
- strValue . match ( decimalPattern ) === null &&
576
- strValue . match ( hexPattern ) === null
577
- ) {
578
- throw new HardhatError (
579
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
580
- {
581
- value : strValue ,
582
- name : argName ,
583
- type : "float" ,
584
- } ,
585
- ) ;
586
- }
587
-
588
- return Number ( strValue ) ;
589
- }
590
-
591
- function validateAndParseBigInt ( argName : string , strValue : string ) : bigint {
592
- const decimalPattern = / ^ \d + (?: n ) ? $ / ;
593
- const hexPattern = / ^ 0 [ x X ] [ \d A B C D E a b c d e ] + $ / ;
594
-
595
- if (
596
- strValue . match ( decimalPattern ) === null &&
597
- strValue . match ( hexPattern ) === null
598
- ) {
599
- throw new HardhatError (
600
- HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE ,
601
- {
602
- value : strValue ,
603
- name : argName ,
604
- type : "bigint" ,
605
- } ,
606
- ) ;
607
- }
608
-
609
- return BigInt ( strValue . replace ( "n" , "" ) ) ;
610
- }
611
-
612
- function validateAndParseBoolean ( argName : string , strValue : string ) : boolean {
613
- if ( strValue . toLowerCase ( ) === "true" ) {
614
- return true ;
615
- }
616
- if ( strValue . toLowerCase ( ) === "false" ) {
617
- return false ;
618
- }
619
-
620
- throw new HardhatError ( HardhatError . ERRORS . ARGUMENTS . INVALID_VALUE_FOR_TYPE , {
621
- value : strValue ,
622
- name : argName ,
623
- type : "boolean" ,
624
- } ) ;
625
- }
0 commit comments