import { die } from "../fmt.ts" import * as config from "../config.ts" const VALID_KEYS = Object.keys(config.DEFAULTS) as config.Key[] export async function action(args: string[]) { if (args.length === 0) { const cfg = await config.load() for (const key of VALID_KEYS) { const val = cfg[key] const display = val ?? `${config.DEFAULTS[key]} (default)` console.log(`${key} = ${display}`) } return } const [key, ...rest] = args if (!VALID_KEYS.includes(key as config.Key)) die(`Unknown config key: ${key}\nAvailable keys: ${VALID_KEYS.join(", ")}`) if (rest.length === 0) { const val = await config.get(key as config.Key) console.log(val ?? `${config.DEFAULTS[key as config.Key]} (default)`) return } if (rest.length > 1) die(`Too many arguments. Usage: sandlot config ${key} `) let normalized: string try { normalized = config.validateMemory(rest[0]) } catch { return die("Must be a number followed by G or M, minimum 512M (e.g. 16G)") } await config.set("memory", normalized) console.log(`memory = ${normalized}`) }