diff --git a/src/commands/proxy-command.ts b/src/commands/proxy-command.ts index 5a2451c1..2aa9d391 100644 --- a/src/commands/proxy-command.ts +++ b/src/commands/proxy-command.ts @@ -22,9 +22,15 @@ function parseOptionValue(args: string[], key: string): string | undefined { return withEquals ? withEquals.slice(prefix.length) : undefined; } -function findPositionalArg(args: string[], optionsWithValues: string[] = []): string | undefined { +export function findPositionalArg( + args: string[], + optionsWithValues: string[] = [] +): string | undefined { for (let i = 0; i < args.length; i += 1) { const arg = args[i]; + if (arg === '--') { + return args[i + 1]; + } if (arg.startsWith('-')) { if (optionsWithValues.includes(arg)) { i += 1; diff --git a/tests/unit/commands/proxy-command.test.ts b/tests/unit/commands/proxy-command.test.ts new file mode 100644 index 00000000..ff71eb90 --- /dev/null +++ b/tests/unit/commands/proxy-command.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'bun:test'; +import { findPositionalArg } from '../../../src/commands/proxy-command'; + +describe('findPositionalArg', () => { + it('skips option values before returning the first positional argument', () => { + expect(findPositionalArg(['--port', '3456', 'ccg'], ['--port'])).toBe('ccg'); + }); + + it('treats arguments after -- as positional', () => { + expect(findPositionalArg(['--', '--port', '3456'], ['--port'])).toBe('--port'); + }); +});