-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow overriding config file with cli flags (closes #419)
- Loading branch information
Showing
4 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Command, OptionValues } from "commander"; | ||
import { logger } from "./logger"; | ||
import { getConfigFileOptions } from "./cli-config"; | ||
import { DEFAULT_CONFIG } from "../../config"; | ||
|
||
export async function configureOptions( | ||
context: string, | ||
options: SWACLIConfig, | ||
command: Command | ||
): Promise<{ context: string; options: SWACLIConfig }> { | ||
const verbose = options.verbose; | ||
process.env.SWA_CLI_DEBUG = verbose; | ||
|
||
if (verbose?.includes("silly")) { | ||
// When silly level is set, | ||
// propagate debugging level to other tools using the DEBUG environment variable | ||
process.env.DEBUG = "*"; | ||
} | ||
|
||
const userOptions = getUserOptions(command); | ||
const configFileOptions = await getConfigFileOptions(context, options.config!); | ||
|
||
options = { | ||
...options, | ||
...configFileOptions, | ||
...userOptions, | ||
}; | ||
|
||
if (options.printConfig) { | ||
logger.log("", "swa"); | ||
logger.log("Options: ", "swa"); | ||
logger.log({ ...DEFAULT_CONFIG, ...options }, "swa"); | ||
} | ||
|
||
return { | ||
context: configFileOptions.context ?? context, | ||
options, | ||
}; | ||
} | ||
|
||
function getUserOptions(command: Command) { | ||
const userOptions: OptionValues = {}; | ||
const options = command.opts(); | ||
for (const option in options) { | ||
if (command.getOptionValueSource(option) !== "default") { | ||
userOptions[option] = options[option]; | ||
} | ||
} | ||
return userOptions as SWACLIConfig; | ||
} |