/** * acr config [--where] — 顯示目前生效的設定與每個值的來源層。 * 解壓測 §1.2 建議 #3:讓使用者一眼確認「現在這個資料夾正用哪個帳號」,避免用錯帳號部署。 * SDD: sdk-and-website/config-layering.md §3.1 */ import chalk from 'chalk'; import { resolveConfigSources, activeProjectConfigPath, type ConfigSource, } from '../lib/config.js'; const SOURCE_LABEL: Record = { env: 'env 變數', project: '專案層 .arcrun.yaml', global: '全域 ~/.arcrun/config.yaml', default: '預設值', }; /** 敏感欄位只印前綴,避免把 token 完整印到終端 / log。*/ const SENSITIVE = new Set(['api_key', 'encryption_key', 'cf_api_token']); function mask(field: string, value: string): string { if (SENSITIVE.has(field) && value.length > 8) return `${value.slice(0, 8)}…`; return value; } export async function cmdConfig(_options: { where?: boolean }): Promise { const rows = resolveConfigSources(); const projectPath = activeProjectConfigPath(); console.log(chalk.bold('\n arcrun 目前生效的設定\n')); if (projectPath) { console.log(chalk.gray(` 專案層設定:${projectPath}(覆蓋全域)`)); } else { console.log(chalk.gray(' 專案層設定:無(此資料夾未放 .arcrun.yaml,使用全域)')); } console.log(''); const fieldWidth = Math.max(...rows.map(r => r.field.length), 4); for (const { field, value, source } of rows) { const name = field.padEnd(fieldWidth); console.log( ` ${chalk.cyan(name)} ${mask(field, value)} ${chalk.gray(`← ${SOURCE_LABEL[source]}`)}`, ); } console.log(chalk.gray('\n 優先序:env 變數 > 專案層 .arcrun.yaml > 全域 ~/.arcrun/config.yaml\n')); }