@@ -16,16 +16,14 @@ interface UserConfig extends Record<string, string> {
1616 projectId : string ;
1717}
1818
19- const cliConfig = argv ( process . argv . slice ( 2 ) ) as unknown as Partial < UserConfig > ;
20-
2119const defaults : UserConfig = {
2220 apiBaseUrl : "https://cloud.mongodb.com/" ,
2321 clientId : "0oabtxactgS3gHIR0297" ,
2422 stateFile : path . join ( localDataPath , "state.json" ) ,
2523 projectId : "" ,
2624} ;
2725
28- const mergedUserConfig = mergeConfigs ( defaults , getFileConfig ( ) , getEnvConfig ( ) , cliConfig ) ;
26+ const mergedUserConfig = Object . assign ( { } , defaults , getFileConfig ( ) , getEnvConfig ( ) , getCliConfig ( ) ) ;
2927
3028const __filename = fileURLToPath ( import . meta. url ) ;
3129const __dirname = path . dirname ( __filename ) ;
@@ -93,17 +91,7 @@ function getFileConfig(): Partial<UserConfig> {
9391 }
9492}
9593
96- // Merges several user-supplied configs into one. The precedence is from right to left where the last
97- // config in the `partialConfigs` array overrides the previous ones. The `defaults` config is used as a base.
98- function mergeConfigs ( defaults : UserConfig , ...partialConfigs : Array < Partial < UserConfig > > ) : UserConfig {
99- const mergedConfig : UserConfig = { ...defaults } ;
100- for ( const key of Object . keys ( defaults ) ) {
101- for ( const partialConfig of partialConfigs ) {
102- if ( partialConfig [ key ] ) {
103- mergedConfig [ key ] = partialConfig [ key ] ;
104- }
105- }
106- }
107-
108- return mergedConfig ;
94+ // Reads the cli args and parses them into a UserConfig object.
95+ function getCliConfig ( ) {
96+ return argv ( process . argv . slice ( 2 ) ) as unknown as Partial < UserConfig > ;
10997}
0 commit comments