@@ -16,16 +16,14 @@ interface UserConfig extends Record<string, string> {
16
16
projectId : string ;
17
17
}
18
18
19
- const cliConfig = argv ( process . argv . slice ( 2 ) ) as unknown as Partial < UserConfig > ;
20
-
21
19
const defaults : UserConfig = {
22
20
apiBaseUrl : "https://cloud.mongodb.com/" ,
23
21
clientId : "0oabtxactgS3gHIR0297" ,
24
22
stateFile : path . join ( localDataPath , "state.json" ) ,
25
23
projectId : "" ,
26
24
} ;
27
25
28
- const mergedUserConfig = mergeConfigs ( defaults , getFileConfig ( ) , getEnvConfig ( ) , cliConfig ) ;
26
+ const mergedUserConfig = Object . assign ( { } , defaults , getFileConfig ( ) , getEnvConfig ( ) , getCliConfig ( ) ) ;
29
27
30
28
const __filename = fileURLToPath ( import . meta. url ) ;
31
29
const __dirname = path . dirname ( __filename ) ;
@@ -93,17 +91,7 @@ function getFileConfig(): Partial<UserConfig> {
93
91
}
94
92
}
95
93
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 > ;
109
97
}
0 commit comments