(action?: string, key?: string, value?: string)
| 15 | ]; |
| 16 | |
| 17 | export async function configCommand(action?: string, key?: string, value?: string) { |
| 18 | if (!(await isInitialized())) { |
| 19 | console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first.")); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | try { |
| 24 | const config = await loadConfig(); |
| 25 | |
| 26 | if (!action || action === "list") { |
| 27 | console.log(chalk.bold("\nDevContext Configuration:\n")); |
| 28 | for (const [k, v] of Object.entries(config)) { |
| 29 | if (k === "aiApiKey" && v) { |
| 30 | console.log(` ${chalk.cyan(k)}: ${chalk.gray("****" + String(v).slice(-4))}`); |
| 31 | } else { |
| 32 | console.log(` ${chalk.cyan(k)}: ${chalk.white(String(v))}`); |
| 33 | } |
| 34 | } |
| 35 | console.log(); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | if (action === "get") { |
| 40 | if (!key) { |
| 41 | console.log(chalk.red("✗ Usage: devctx config get <key>")); |
| 42 | return; |
| 43 | } |
| 44 | if (!VALID_KEYS.includes(key as keyof UserConfig)) { |
| 45 | console.log(chalk.red(`✗ Unknown config key: ${key}`)); |
| 46 | console.log(chalk.gray(` Valid keys: ${VALID_KEYS.join(", ")}`)); |
| 47 | return; |
| 48 | } |
| 49 | const val = config[key as keyof UserConfig]; |
| 50 | console.log(`${chalk.cyan(key)}: ${chalk.white(String(val ?? "(not set)"))}`); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (action === "set") { |
| 55 | if (!key || value === undefined) { |
| 56 | console.log(chalk.red("✗ Usage: devctx config set <key> <value>")); |
| 57 | return; |
| 58 | } |
| 59 | if (!VALID_KEYS.includes(key as keyof UserConfig)) { |
| 60 | console.log(chalk.red(`✗ Unknown config key: ${key}`)); |
| 61 | console.log(chalk.gray(` Valid keys: ${VALID_KEYS.join(", ")}`)); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | // Type coercion |
| 66 | let typedValue: any = value; |
| 67 | if (value === "true") typedValue = true; |
| 68 | else if (value === "false") typedValue = false; |
| 69 | else if (!isNaN(Number(value)) && key !== "aiApiKey" && key !== "aiProvider" && key !== "aiModel") { |
| 70 | typedValue = Number(value); |
| 71 | } |
| 72 | |
| 73 | await saveConfig({ [key]: typedValue }); |
| 74 | console.log(chalk.green(`✓ Set ${chalk.bold(key)} = ${typedValue}`)); |
nothing calls this directly
no test coverage detected