diff --git a/src/commands/proxy-command.ts b/src/commands/proxy-command.ts index 88365c4f..29b41c87 100644 --- a/src/commands/proxy-command.ts +++ b/src/commands/proxy-command.ts @@ -22,6 +22,10 @@ function parseOptionValue(args: string[], key: string): string | undefined { return withEquals ? withEquals.slice(prefix.length) : undefined; } +function hasHelpFlag(args: string[]): boolean { + return args.includes('--help') || args.includes('-h'); +} + export function findPositionalArg( args: string[], optionsWithValues: string[] = [] @@ -83,6 +87,9 @@ function resolveProfile(profileName: string) { } async function handleStart(args: string[]): Promise { + if (hasHelpFlag(args)) { + return showHelp(); + } const profileName = findPositionalArg(args, ['--port', '--host']); if (!profileName) { console.error( @@ -122,6 +129,9 @@ async function handleStart(args: string[]): Promise { } async function handleStatus(args: string[] = []): Promise { + if (hasHelpFlag(args)) { + return showHelp(); + } const profileName = findPositionalArg(args); const running = profileName ? [await getOpenAICompatProxyStatus(profileName)].filter((status) => status.running) @@ -150,6 +160,9 @@ async function handleStatus(args: string[] = []): Promise { } async function handleActivate(args: string[]): Promise { + if (hasHelpFlag(args)) { + return showHelp(); + } const profileName = findPositionalArg(args, ['--shell']); if (!profileName) { const running = (await listOpenAICompatProxyStatuses()).filter((entry) => entry.running); @@ -199,6 +212,9 @@ export async function handleProxyCommand(args: string[]): Promise { case 'start': return handleStart(args.slice(1)); case 'stop': { + if (hasHelpFlag(args.slice(1))) { + return showHelp(); + } const profileName = args[1] && !args[1].startsWith('-') ? args[1] : undefined; const result = await stopOpenAICompatProxy(profileName); if (!result.success) { diff --git a/tests/e2e/proxy-command.e2e.test.ts b/tests/e2e/proxy-command.e2e.test.ts index 47029bb5..8c2a0f62 100644 --- a/tests/e2e/proxy-command.e2e.test.ts +++ b/tests/e2e/proxy-command.e2e.test.ts @@ -45,6 +45,13 @@ afterEach(() => { }); describe('proxy command e2e', () => { + it('shows help for subcommand help flags without executing the subcommand', () => { + const help = runCli(['proxy', 'stop', '--help']); + expect(help.status).toBe(0); + expect(help.stdout).toContain('Usage: ccs proxy [profile] [options]'); + expect(help.stdout).toContain('stop [profile] Stop the running proxy (or all proxies when omitted)'); + }); + it('starts, reports status, activates, and stops via the built CLI', async () => { const port = await getPort(); const ccsDir = path.join(tempDir, '.ccs');