(args: string[])
| 3 | const VALID_KEYS: (keyof Config)[] = ["api_key", "api_url", "agent_email", "shared_domain"]; |
| 4 | |
| 5 | export async function config(args: string[]): Promise<void> { |
| 6 | const subcommand = args[0]; |
| 7 | |
| 8 | if (!subcommand || subcommand === "list") { |
| 9 | showAll(); |
| 10 | return; |
| 11 | } |
| 12 | |
| 13 | if (subcommand === "get") { |
| 14 | const key = args[1]; |
| 15 | if (!key) { |
| 16 | process.stderr.write("Usage: e2a config get <key>\n"); |
| 17 | process.exit(1); |
| 18 | } |
| 19 | if (!VALID_KEYS.includes(key as keyof Config)) { |
| 20 | process.stderr.write(`Unknown key: ${key}\nValid keys: ${VALID_KEYS.join(", ")}\n`); |
| 21 | process.exit(1); |
| 22 | } |
| 23 | const cfg = loadConfig(); |
| 24 | const value = cfg[key as keyof Config]; |
| 25 | if (value) { |
| 26 | process.stdout.write(`${value}\n`); |
| 27 | } |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | if (subcommand === "set") { |
| 32 | const key = args[1]; |
| 33 | const value = args[2]; |
| 34 | if (!key || value === undefined) { |
| 35 | process.stderr.write("Usage: e2a config set <key> <value>\n"); |
| 36 | process.exit(1); |
| 37 | } |
| 38 | if (!VALID_KEYS.includes(key as keyof Config)) { |
| 39 | process.stderr.write(`Unknown key: ${key}\nValid keys: ${VALID_KEYS.join(", ")}\n`); |
| 40 | process.exit(1); |
| 41 | } |
| 42 | saveConfig({ [key]: value }); |
| 43 | process.stdout.write(`${key}=${value}\n`); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // Treat bare key as shorthand for "get" |
| 48 | if (VALID_KEYS.includes(subcommand as keyof Config)) { |
| 49 | const cfg = loadConfig(); |
| 50 | const value = cfg[subcommand as keyof Config]; |
| 51 | if (value) { |
| 52 | process.stdout.write(`${value}\n`); |
| 53 | } |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | process.stderr.write( |
| 58 | "Usage: e2a config [list|get <key>|set <key> <value>]\n" + |
| 59 | `Valid keys: ${VALID_KEYS.join(", ")}\n`, |
| 60 | ); |
| 61 | process.exit(1); |
| 62 | } |
no test coverage detected