66 FilecoinFlavorName
77} from "@ganache/flavors" ;
88import { Definitions } from "@ganache/options" ;
9+ import { serverDefaults } from "@ganache/core" ;
910
1011const COLORS = {
1112 Bold : "\x1b[1m" ,
@@ -14,6 +15,65 @@ const COLORS = {
1415 FgYellow : "\x1b[33m"
1516} ;
1617
18+ function processOption (
19+ category : string ,
20+ option : string ,
21+ optionObj : Definitions < any > [ string | number ] ,
22+ argv : yargs . Argv
23+ ) {
24+ if ( optionObj . disableInCLI !== true ) {
25+ const group = `${ category . charAt ( 0 ) . toUpperCase ( ) } ${ category . substr ( 1 ) } :` ;
26+
27+ const useAliases = typeof optionObj . cliAliases !== "undefined" ;
28+ const alias = useAliases
29+ ? optionObj . cliAliases
30+ : ( optionObj as any ) . legacyName ;
31+
32+ let description = optionObj . shortDescription ;
33+ if (
34+ alias &&
35+ ( ! Array . isArray ( alias ) || alias . filter ( a => a . length > 1 ) . length > 0 )
36+ ) {
37+ description = `${ description } \n${ COLORS . Bold } ${
38+ COLORS . FgYellow
39+ } Deprecated aliases: ${
40+ Array . isArray ( alias )
41+ ? alias . filter ( a => a . length > 1 ) . join ( ", " )
42+ : alias
43+ } ${ COLORS . Reset } \n`;
44+ }
45+
46+ let defaultValue ;
47+ try {
48+ const defaultGetter = ( optionObj as any ) . default ;
49+ if ( defaultGetter && defaultGetter . length > 0 ) {
50+ defaultValue = defaultGetter ( ) ;
51+ }
52+ } catch ( e ) { }
53+ if ( optionObj . cliType === "array" && ! Array . isArray ( defaultValue ) ) {
54+ // if we pass `default: undefined`, yargs will return `[ undefined ]`
55+ // this just explicitly fixes array types
56+
57+ if ( typeof defaultValue === "undefined" ) {
58+ defaultValue = [ ] ;
59+ } else {
60+ defaultValue = [ defaultValue ] ;
61+ }
62+ }
63+
64+ argv = argv . option ( `${ category } .${ option } ` , {
65+ group,
66+ description,
67+ alias,
68+ default : defaultValue ,
69+ defaultDescription : ( optionObj as any ) . defaultDescription ,
70+ type : optionObj . cliChoices ? undefined : optionObj . cliType ,
71+ choices : optionObj . cliChoices ,
72+ coerce : optionObj . normalize
73+ } ) ;
74+ }
75+ }
76+
1777export default function ( version : string , isDocker : boolean ) {
1878 let args = yargs . strict ( ) ;
1979
@@ -43,73 +103,29 @@ export default function (version: string, isDocker: boolean) {
43103 hidden : true
44104 } ) ;
45105
46- const group = `${ category . charAt ( 0 ) . toUpperCase ( ) } ${ category . substr (
47- 1
48- ) } :`;
49106 const categoryObj = flavorDefaults [ category ] as Definitions < any > ;
50107 const options = Object . keys ( categoryObj ) ;
51108 for ( const option of options ) {
52109 const optionObj = categoryObj [ option ] ;
53- if ( optionObj . disableInCLI !== true ) {
54- const useAliases = typeof optionObj . cliAliases !== "undefined" ;
55- const alias = useAliases
56- ? optionObj . cliAliases
57- : ( optionObj as any ) . legacyName ;
58-
59- let description = optionObj . shortDescription ;
60- if (
61- alias &&
62- ( ! Array . isArray ( alias ) ||
63- alias . filter ( a => a . length > 1 ) . length > 0 )
64- ) {
65- description = `${ description } \n${ COLORS . Bold } ${
66- COLORS . FgYellow
67- } Deprecated aliases: ${
68- Array . isArray ( alias )
69- ? alias . filter ( a => a . length > 1 ) . join ( ", " )
70- : alias
71- } ${ COLORS . Reset } \n`;
72- }
73-
74- let defaultValue ;
75- try {
76- const defaultGetter = ( optionObj as any ) . default ;
77- if ( defaultGetter && defaultGetter . length > 0 ) {
78- defaultValue = defaultGetter ( ) ;
79- }
80- } catch ( e ) { }
81- if (
82- optionObj . cliType === "array" &&
83- ! Array . isArray ( defaultValue )
84- ) {
85- // if we pass `default: undefined`, yargs will return `[ undefined ]`
86- // this just explicitly fixes array types
87-
88- if ( typeof defaultValue === "undefined" ) {
89- defaultValue = [ ] ;
90- } else {
91- defaultValue = [ defaultValue ] ;
92- }
93- }
94-
95- flavorArgs = flavorArgs . option ( `${ category } .${ option } ` , {
96- group,
97- description,
98- alias,
99- default : defaultValue ,
100- defaultDescription : ( optionObj as any ) . defaultDescription ,
101- type : optionObj . cliChoices ? undefined : optionObj . cliType ,
102- choices : optionObj . cliChoices ,
103- coerce : optionObj . normalize
104- } ) ;
105- }
110+ processOption ( category , option , optionObj , flavorArgs ) ;
111+ }
112+ }
113+
114+ flavorArgs = flavorArgs . option ( "server" , { hidden : true } ) ;
115+
116+ const categoryObj = serverDefaults . server ;
117+ const options = Object . keys ( categoryObj ) ;
118+ for ( const option of options ) {
119+ const optionObj = categoryObj [ option ] ;
120+
121+ if ( option === "rpcEndpoint" && flavor === FilecoinFlavorName ) {
122+ optionObj . default = ( ) => "/rpc/v0" ;
106123 }
124+
125+ processOption ( "server" , option , optionObj , flavorArgs ) ;
107126 }
108127
109128 flavorArgs = flavorArgs
110- . option ( "server" , {
111- hidden : true
112- } )
113129 . option ( "server.host" , {
114130 group : "Server:" ,
115131 description : `Hostname to listen on.\n${ COLORS . Bold } ${ COLORS . FgYellow } Deprecated aliases: host, hostname${ COLORS . Reset } \n` ,
0 commit comments