import path from "node:path"; import * as c from "yoctocolors"; import { ENV_MAPPING, MystEnvironmentVariables, parseEnvFile } from "../config.js"; function redactSecret(value: string | undefined): string { if (!value) return c.dim("not set"); if (value.length <= 4) return c.dim("****"); return value.slice(0, 4) + c.dim("****"); } export async function configCommand(): Promise { const envPath = path.join(process.cwd(), ".env"); let config: Partial; try { config = parseEnvFile(envPath); } catch (error) { const err = error as NodeJS.ErrnoException; if (err.code === "ENOENT") { process.stderr.write( `${c.red("Error:")} .env file not found in ${process.cwd()}\n`, ); process.exitCode = 1; return; } throw error; } process.stdout.write(c.bold("Myst Configuration\n")); process.stdout.write(`${c.dim("─".repeat(40))}\n`); for (const [envKey, configKey] of Object.entries(ENV_MAPPING)) { const value = config[configKey]; const displayValue = configKey === "forgejoPat" || configKey === "grantTokenSecret" ? redactSecret(value) : value || c.dim("not set"); process.stdout.write(`${c.bold(envKey + ":")} ${displayValue}\n`); } process.exitCode = 0; }