Skip to content

Commit 422c44e

Browse files
committed
🐛 fix CLI defaults overriding env vars & config.json #2357
1 parent b2bfc2c commit 422c44e

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/cli/setup.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ const optionList:
252252

253253
export const optionKeys = optionList.map(({ name }) => camelize(name));
254254

255+
export const optionKeysWithDefalts = optionList.filter(o=>o.hasOwnProperty('default')).map(({ name }) => camelize(name));
256+
255257
export const PrimitiveConverter = {
256258
Number : 1,
257259
Boolean : true,
@@ -370,23 +372,36 @@ export const cli: () => {
370372
* 3. CLI flags
371373
*/
372374

375+
const nonCliConfigs = {
376+
/**
377+
* Environmental Variables
378+
*/
379+
...envArgs(),
380+
/**
381+
* The configuration file OR the --config base64 encoded config object
382+
*/
383+
...(configFile(_cli.flags.config as string) || {}),
384+
}
385+
386+
optionList.filter(option=>option.default)
387+
373388
const cliConfig: any = {
374389
sessionId: "session",
375390
/**
376391
* Prioirity goes from bottom up
377392
*/
393+
...nonCliConfigs,
378394
/**
379-
* Environmental Variables
380-
*/
381-
...envArgs(),
382-
/**
383-
* The configuration file OR the --config base64 encoded config object
395+
* CLI flags
384396
*/
385-
...(configFile(_cli.flags.config as string) || {}),
397+
..._cli.flags,
386398
/**
387-
* CLI flags
399+
* Grab the configs for the cli defaults
388400
*/
389-
..._cli.flags
401+
...optionKeysWithDefalts.reduce((p,c)=> nonCliConfigs.hasOwnProperty(c) ? {
402+
...p,
403+
[c]:nonCliConfigs[c]
404+
} : p,{})
390405
};
391406

392407
const PORT = Number(cliConfig.port || process.env.PORT || 8080);

0 commit comments

Comments
 (0)