mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 08:19:59 +00:00
fix(proxy): handle end-of-options parsing
This commit is contained in:
@@ -22,9 +22,15 @@ function parseOptionValue(args: string[], key: string): string | undefined {
|
|||||||
return withEquals ? withEquals.slice(prefix.length) : 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) {
|
for (let i = 0; i < args.length; i += 1) {
|
||||||
const arg = args[i];
|
const arg = args[i];
|
||||||
|
if (arg === '--') {
|
||||||
|
return args[i + 1];
|
||||||
|
}
|
||||||
if (arg.startsWith('-')) {
|
if (arg.startsWith('-')) {
|
||||||
if (optionsWithValues.includes(arg)) {
|
if (optionsWithValues.includes(arg)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|||||||
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user