mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 12:15:57 +00:00
fix(env): improve empty profile UX and consolidate shell validation constants
- Return {} instead of null for valid-but-empty settings profiles
- Consolidate VALID_SHELLS and validShellInputs into VALID_SHELL_INPUTS
- Fix docs test count 33 → 34
This commit is contained in:
@@ -276,7 +276,7 @@ CCS provides:
|
||||
- [x] Settings profile support (glm, kimi, custom API)
|
||||
- [x] Security: single-quoted output, key sanitization, shell-specific escaping
|
||||
- [x] Shell completion updated (bash, zsh, fish, PowerShell)
|
||||
- [x] 33 unit tests for env command
|
||||
- [x] 34 unit tests for env command
|
||||
|
||||
### v8.0 Release (Planned - Q1 2026)
|
||||
- [ ] Multiple CLIProxyAPI instances (load balancing, failover)
|
||||
|
||||
@@ -20,6 +20,7 @@ type OutputFormat = 'openai' | 'anthropic' | 'raw';
|
||||
|
||||
const VALID_FORMATS: OutputFormat[] = ['openai', 'anthropic', 'raw'];
|
||||
const VALID_SHELLS: ShellType[] = ['bash', 'fish', 'powershell'];
|
||||
const VALID_SHELL_INPUTS = ['auto', 'bash', 'zsh', 'fish', 'powershell'] as const;
|
||||
const VALID_ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
||||
|
||||
/** Auto-detect shell from environment */
|
||||
@@ -122,11 +123,10 @@ function resolveSettingsProfile(profileName: string): Record<string, string> | n
|
||||
|
||||
if (profileConfig.settings) {
|
||||
const settingsPath = expandPath(profileConfig.settings);
|
||||
const env = loadSettingsFromFile(settingsPath);
|
||||
if (Object.keys(env).length > 0) return env;
|
||||
return loadSettingsFromFile(settingsPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
return {};
|
||||
}
|
||||
|
||||
/** Show help for env command */
|
||||
@@ -206,9 +206,8 @@ export async function handleEnvCommand(args: string[]): Promise<void> {
|
||||
const format = formatStr as OutputFormat;
|
||||
|
||||
const shellStr = parseFlag(args, 'shell') || 'auto';
|
||||
const validShellInputs = ['auto', 'bash', 'zsh', 'fish', 'powershell'];
|
||||
if (!validShellInputs.includes(shellStr)) {
|
||||
console.error(fail(`Invalid shell: ${shellStr}. Use: ${validShellInputs.join(', ')}`));
|
||||
if (!VALID_SHELL_INPUTS.includes(shellStr as (typeof VALID_SHELL_INPUTS)[number])) {
|
||||
console.error(fail(`Invalid shell: ${shellStr}. Use: ${VALID_SHELL_INPUTS.join(', ')}`));
|
||||
process.exit(1);
|
||||
}
|
||||
// zsh uses the same syntax as bash
|
||||
|
||||
Reference in New Issue
Block a user