(source: string)
| 134 | // Merge a --values file (the base) with explicit flags (which win). Provider |
| 135 | // keys merge per provider; the scalar flags override only when actually set. |
| 136 | // An invalid --log-level exits 1 — loud like a bad values file, not silent. |
| 137 | export function partialFromFlags(flags: RawFlags, fileValues: Partial<DeployConfig>): Partial<DeployConfig> { |
| 138 | const llmKeys: Record<string, string> = { ...(fileValues.llmKeys ?? {}), ...flags.llmKeys }; |
| 139 | |
| 140 | // Same schema the values file is checked against — one list of valid levels. |
| 141 | let flagLogLevel: LogLevel | undefined; |
| 142 | if (flags.logLevel !== undefined) { |
| 143 | const checked = logLevelSchema.safeParse(flags.logLevel); |
| 144 | if (!checked.success) { |
| 145 | process.stderr.write(`Invalid --log-level "${flags.logLevel}" — expected ${logLevelSchema.options.join("|")}.\n`); |
| 146 | process.exit(1); |
| 147 | } |
| 148 | flagLogLevel = checked.data; |
| 149 | } |
| 150 | |
| 151 | return { |
| 152 | ...fileValues, |
| 153 | llmKeys, |
| 154 | ...(flags.output !== undefined ? { outputDir: flags.output } : {}), |
| 155 | ...(flags.force ? { force: true } : {}), |
| 156 | ...(flagLogLevel ? { logLevel: flagLogLevel } : {}), |
| 157 | }; |
| 158 | } |
| 159 | |
| 160 | // Load a --values file: a partial DeployConfig as JSON. Never logged (may carry |
| 161 | // secrets). Exits 1 on a missing file, malformed JSON, or content that doesn't |
| 162 | // match valuesFileSchema (wrong types, unknown keys) — listing every problem as |
| 163 | // a `path: reason` line so a non-interactive caller can fix the file. |
| 164 | export async function loadValues(source: string): Promise<Partial<DeployConfig>> { |
| 165 | const abs = path.resolve(process.cwd(), source); |
| 166 | let raw: string; |
| 167 | try { |
| 168 | raw = await fs.readFile(abs, "utf-8"); |
| 169 | } catch (err: unknown) { |
| 170 | if ((err as NodeJS.ErrnoException).code === "ENOENT") { |
| 171 | process.stderr.write(`Values file not found: ${abs}\n`); |
| 172 | process.exit(1); |
no test coverage detected