diff --git a/projects/optic/src/config.ts b/projects/optic/src/config.ts index 5c06f9e86e..47e4e17a52 100644 --- a/projects/optic/src/config.ts +++ b/projects/optic/src/config.ts @@ -285,7 +285,9 @@ async function getYmlOrJsonChanges(gitRoot: string): Promise> { return new Set(ymlOrJsonWithChanges); } -export async function initializeConfig(): Promise { +export async function initializeConfig( + opticYml: string | undefined +): Promise { let cliConfig: OpticCliConfig = DefaultOpticCliConfig; const userConfig = await readUserConfig(); const maybeEnvToken = process.env.OPTIC_TOKEN; @@ -306,7 +308,14 @@ export async function initializeConfig(): Promise { 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); diff --git a/projects/optic/src/init.ts b/projects/optic/src/init.ts index d894fc075f..4b1988f035 100644 --- a/projects/optic/src/init.ts +++ b/projects/optic/src/init.ts @@ -109,8 +109,14 @@ export const initCli = async ( let cliConfig: OpticCliConfig; + cli.option('-f , --file ', '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);