diff --git a/src/commands/proxy-command.ts b/src/commands/proxy-command.ts index 391ad05e..119cc90e 100644 --- a/src/commands/proxy-command.ts +++ b/src/commands/proxy-command.ts @@ -28,7 +28,8 @@ function hasHelpFlag(args: string[]): boolean { export function findPositionalArg( args: string[], - optionsWithValues: string[] = [] + optionsWithValues: string[] = [], + flagOptions: string[] = [] ): string | undefined { for (let i = 0; i < args.length; i += 1) { const arg = args[i]; @@ -36,6 +37,9 @@ export function findPositionalArg( return i + 1 < args.length ? args[i + 1] : undefined; } if (arg.startsWith('-')) { + if (flagOptions.includes(arg)) { + continue; + } if (optionsWithValues.includes(arg)) { i += 1; } @@ -90,7 +94,7 @@ async function handleStart(args: string[]): Promise { if (hasHelpFlag(args)) { return showHelp(); } - const profileName = findPositionalArg(args, ['--port', '--host']); + const profileName = findPositionalArg(args, ['--port', '--host'], ['--insecure']); if (!profileName) { console.error( fail('Usage: ccs proxy start [--port ] [--host ] [--insecure]') diff --git a/tests/unit/commands/proxy-command.test.ts b/tests/unit/commands/proxy-command.test.ts index a1913dfc..a3db75b1 100644 --- a/tests/unit/commands/proxy-command.test.ts +++ b/tests/unit/commands/proxy-command.test.ts @@ -6,6 +6,12 @@ describe('findPositionalArg', () => { expect(findPositionalArg(['--port', '3456', 'ccg'], ['--port'])).toBe('ccg'); }); + it('skips flag options that do not take values', () => { + expect(findPositionalArg(['--insecure', 'ccg'], ['--port', '--host'], ['--insecure'])).toBe( + 'ccg' + ); + }); + it('treats arguments after -- as positional', () => { expect(findPositionalArg(['--', '--port', '3456'], ['--port'])).toBe('--port'); });