1/**2 * Helpers shared by the lofi command entrypoints: the doctor-gated command3 * environment and a fail-fast exit for child-process results.4 *5 * @module6 */78import { doctorReport, printDoctorReport } from "../tooling/diagnostics.ts";9import { childEnvironment } from "../tooling/environment.ts";1011/**12 * Run the doctor preflight and return the validated environment for child13 * processes. Prints the doctor report and exits the process when a blocker is14 * found; warnings are printed and the command proceeds.15 *16 * @returns The environment variables the command's child processes receive.17 */18export async function validatedCommandEnvironment(): Promise<Record<string, string>> {19 const report = await doctorReport();20 if (report.blocked || !report.validation.ok) {21 printDoctorReport(report);22 console.error(23 "error: lofi preflight found blockers; apply the printed action and rerun the command",24 );25 Deno.exit(1);26 }27 for (const warning of report.validation.warnings) console.warn(`warning: ${warning}`);28 return childEnvironment(report.validation);29}3031/**32 * Return when `exitCode` is zero; otherwise point at the failed action and33 * exit the process with the same code.34 *35 * @param exitCode The child process's exit code.36 * @param action The name of the step, used in the failure message.37 */38export function exitOnFailure(exitCode: number, action: string): void {39 if (exitCode === 0) return;40 console.error(`error: ${action} failed; fix the first error above and rerun the same Deno task`);41 Deno.exit(exitCode);42}