feat: Add cw account extract CLI command with tests
Adds `cw account extract [--email <email>]` subcommand to the accountCommand group. Reads directly from the local Claude config via extractCurrentClaudeAccount() without requiring a server connection. Supports optional email verification, outputting JSON with email, configJson (stringified), and credentials fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1334,6 +1334,32 @@ export function createCli(serverHandler?: (port?: number) => Promise<void>): Com
|
||||
}
|
||||
});
|
||||
|
||||
// cw account extract
|
||||
accountCommand
|
||||
.command('extract')
|
||||
.description('Extract current Claude credentials for use with the UI (does not require server)')
|
||||
.option('--email <email>', 'Verify extracted account matches this email')
|
||||
.action(async (options: { email?: string }) => {
|
||||
try {
|
||||
const { extractCurrentClaudeAccount } = await import('../agent/accounts/index.js');
|
||||
const extracted = await extractCurrentClaudeAccount();
|
||||
if (options.email && extracted.email !== options.email) {
|
||||
console.error(`Account '${options.email}' not found (active account is '${extracted.email}')`);
|
||||
process.exit(1);
|
||||
return;
|
||||
}
|
||||
const output = {
|
||||
email: extracted.email,
|
||||
configJson: JSON.stringify(extracted.configJson),
|
||||
credentials: extracted.credentials,
|
||||
};
|
||||
console.log(JSON.stringify(output, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Failed to extract account:', (error as Error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Preview command group
|
||||
const previewCommand = program
|
||||
.command('preview')
|
||||
|
||||
Reference in New Issue
Block a user