The config command previously maintained a separate key list and used a switch statement that would need updating for each new key. Deriving VALID_KEYS from config.DEFAULTS keeps them in sync automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
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} <value>`)
|
|
|
|
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}`)
|
|
}
|