mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 14:16:43 +00:00
Merge pull request #107 from kaitranntt/kai/fix/auth-create-default-warning
fix(auth): improve default account hint and add reset-default command
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
info,
|
||||
table,
|
||||
infoBox,
|
||||
warnBox,
|
||||
} from '../utils/ui';
|
||||
import { getClaudeCliInfo } from '../utils/claude-detector';
|
||||
import { escapeShellArg } from '../utils/shell-executor';
|
||||
@@ -98,6 +99,9 @@ class AuthCommands {
|
||||
console.log(` ${color('show <profile>', 'command')} Show profile details`);
|
||||
console.log(` ${color('remove <profile>', 'command')} Remove saved profile`);
|
||||
console.log(` ${color('default <profile>', 'command')} Set default profile`);
|
||||
console.log(
|
||||
` ${color('reset-default', 'command')} Clear default (restore original CCS)`
|
||||
);
|
||||
console.log('');
|
||||
console.log(subheader('Examples'));
|
||||
console.log(` ${dim('# Create & login to work profile')}`);
|
||||
@@ -106,6 +110,9 @@ class AuthCommands {
|
||||
console.log(` ${dim('# Set work as default')}`);
|
||||
console.log(` ${color('ccs auth default work', 'command')}`);
|
||||
console.log('');
|
||||
console.log(` ${dim('# Restore original CCS behavior')}`);
|
||||
console.log(` ${color('ccs auth reset-default', 'command')}`);
|
||||
console.log('');
|
||||
console.log(` ${dim('# List all profiles')}`);
|
||||
console.log(` ${color('ccs auth list', 'command')}`);
|
||||
console.log('');
|
||||
@@ -252,8 +259,17 @@ class AuthCommands {
|
||||
console.log(header('Usage'));
|
||||
console.log(` ${color(`ccs ${profileName} "your prompt here"`, 'command')}`);
|
||||
console.log('');
|
||||
console.log('To set as default (so you can use just "ccs"):');
|
||||
console.log(` ${color(`ccs auth default ${profileName}`, 'command')}`);
|
||||
console.log(
|
||||
warnBox(
|
||||
`Running the command below will SWITCH your default\n` +
|
||||
`CCS account to "${profileName}". After this, running\n` +
|
||||
`"ccs" without a profile name will use this account.\n\n` +
|
||||
` ${color(`ccs auth default ${profileName}`, 'command')}\n\n` +
|
||||
`To restore the original default, run:\n` +
|
||||
` ${color('ccs auth reset-default', 'command')}`,
|
||||
'Set as Default?'
|
||||
)
|
||||
);
|
||||
console.log('');
|
||||
process.exit(0);
|
||||
} else {
|
||||
@@ -611,6 +627,32 @@ class AuthCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset default profile (clear the custom default, restore original CCS behavior)
|
||||
*/
|
||||
async handleResetDefault(): Promise<void> {
|
||||
await initUI();
|
||||
|
||||
try {
|
||||
// Use unified or legacy based on config mode
|
||||
if (this.isUnifiedMode()) {
|
||||
this.registry.clearDefaultUnified();
|
||||
} else {
|
||||
this.registry.clearDefaultProfile();
|
||||
}
|
||||
|
||||
console.log(ok('Default profile cleared'));
|
||||
console.log('');
|
||||
console.log('CCS will now use the original behavior:');
|
||||
console.log(` ${dim('# Uses your primary Claude account')}`);
|
||||
console.log(` ${color('ccs "your prompt"', 'command')}`);
|
||||
console.log('');
|
||||
} catch (error) {
|
||||
console.log(fail((error as Error).message));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Route auth command to appropriate handler
|
||||
*/
|
||||
@@ -653,6 +695,10 @@ class AuthCommands {
|
||||
await this.handleDefault(commandArgs);
|
||||
break;
|
||||
|
||||
case 'reset-default':
|
||||
await this.handleResetDefault();
|
||||
break;
|
||||
|
||||
case 'current':
|
||||
await initUI();
|
||||
console.log(warn('Command "current" has been removed'));
|
||||
|
||||
@@ -217,6 +217,15 @@ export class ProfileRegistry {
|
||||
this._write(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear default profile (restore original CCS behavior)
|
||||
*/
|
||||
clearDefaultProfile(): void {
|
||||
const data = this._read();
|
||||
data.default = null;
|
||||
this._write(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if profile exists
|
||||
*/
|
||||
@@ -284,6 +293,15 @@ export class ProfileRegistry {
|
||||
saveUnifiedConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear default profile in unified config (restore original CCS behavior)
|
||||
*/
|
||||
clearDefaultUnified(): void {
|
||||
const config = loadOrCreateUnifiedConfig();
|
||||
config.default = undefined;
|
||||
saveUnifiedConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if account exists in unified config
|
||||
*/
|
||||
|
||||
@@ -141,6 +141,8 @@ Claude Code Profile & Model Switcher`.trim();
|
||||
['ccs auth --help', 'Show account management commands'],
|
||||
['ccs auth create <name>', 'Create new account profile'],
|
||||
['ccs auth list', 'List all account profiles'],
|
||||
['ccs auth default <name>', 'Set default profile'],
|
||||
['ccs auth reset-default', 'Restore original CCS default'],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -301,6 +301,18 @@ export function infoBox(content: string, title?: string): string {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Render warning box (yellow border)
|
||||
*/
|
||||
export function warnBox(content: string, title = 'WARNING'): string {
|
||||
return box(content, {
|
||||
title,
|
||||
borderColor: 'yellow',
|
||||
borderStyle: 'round',
|
||||
padding: 1,
|
||||
});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// TABLE RENDERING
|
||||
// =============================================================================
|
||||
@@ -613,6 +625,7 @@ export const ui = {
|
||||
box,
|
||||
errorBox,
|
||||
infoBox,
|
||||
warnBox,
|
||||
table,
|
||||
|
||||
// Progress
|
||||
|
||||
Reference in New Issue
Block a user