Skip to content

Commit

Permalink
load optic config from --file if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
notnmeyer committed Sep 21, 2023
1 parent d830b7b commit 083feeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 11 additions & 2 deletions projects/optic/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ async function getYmlOrJsonChanges(gitRoot: string): Promise<Set<string>> {
return new Set(ymlOrJsonWithChanges);
}

export async function initializeConfig(): Promise<OpticCliConfig> {
export async function initializeConfig(
opticYml: string | undefined
): Promise<OpticCliConfig> {
let cliConfig: OpticCliConfig = DefaultOpticCliConfig;
const userConfig = await readUserConfig();
const maybeEnvToken = process.env.OPTIC_TOKEN;
Expand All @@ -306,7 +308,14 @@ export async function initializeConfig(): Promise<OpticCliConfig> {
cliConfig.client = createOpticClient(token);
}

if ((await Git.hasGit()) && (await Git.isInGitRepo())) {
if (opticYml) {
logger.debug(`Using config manually specified at ${opticYml}`);
cliConfig = {
...cliConfig,
...(await loadCliConfig(opticYml, cliConfig.client)),
isDefaultConfig: false,
};
} else if ((await Git.hasGit()) && (await Git.isInGitRepo())) {
const gitRoot = await Git.getRootPath();
const opticYmlPath = await detectCliConfig(gitRoot);

Expand Down
8 changes: 7 additions & 1 deletion projects/optic/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ export const initCli = async (

let cliConfig: OpticCliConfig;

cli.option('-f , --file <path>', 'The path to the desired optic.yml file');
cli.parse();
console.log(`NATE: --file=${cli.opts().file}`);

try {
cliConfig = await initializeConfig();
cliConfig = cli.opts().file
? await initializeConfig(cli.opts().file)
: await initializeConfig(undefined);
} catch (e) {
logger.error(chalk.red('Error initializing the cli config'));
logger.error((e as Error).message);
Expand Down

0 comments on commit 083feeb

Please sign in to comment.