mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(proxy): honor subcommand help flags
This commit is contained in:
@@ -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<number> {
|
||||
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<number> {
|
||||
}
|
||||
|
||||
async function handleStatus(args: string[] = []): Promise<number> {
|
||||
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<number> {
|
||||
}
|
||||
|
||||
async function handleActivate(args: string[]): Promise<number> {
|
||||
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<number> {
|
||||
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) {
|
||||
|
||||
@@ -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 <start|stop|status|activate> [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');
|
||||
|
||||
Reference in New Issue
Block a user