From 00ed5034ab6d79c67cdb94a842dfd02704e685f7 Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Sun, 29 Nov 2026 17:48:11 +0330 Subject: [PATCH 1/2] add failing tests --- tests/cli.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/cli.test.ts b/tests/cli.test.ts index e46c43b..c6442ec 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -81,6 +81,27 @@ describe.each(cliTools)('cli completion tests for %s', (cliTool) => { }); }); + describe('inline option value handling', () => { + test.each(['--port=3000', '-p=3000'])( + 'should complete subcommands after %s', + async (option) => { + const output = await runCommand(`${commandPrefix} dev ${option} ""`); + expect(output).toContain('build'); + expect(output).toContain('start'); + } + ); + + test.each(['--port=3000', '-p=3000'])( + 'should not swallow a following subcommand after %s', + async (option) => { + const output = await runCommand( + `${commandPrefix} dev ${option} build ""` + ); + expect(output.trim()).toBe(':4'); + } + ); + }); + describe('boolean option handling', () => { it('should complete subcommands and arguments after boolean options', async () => { const command = `${commandPrefix} dev --verbose ""`; From 78d2c5dc4daaec9035499817c72ec5a064f82018 Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Sun, 29 Nov 2026 17:55:04 +0330 Subject: [PATCH 2/2] fix: handle completions after inline option values --- .changeset/public-bats-start.md | 5 +++++ src/t.ts | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .changeset/public-bats-start.md diff --git a/.changeset/public-bats-start.md b/.changeset/public-bats-start.md new file mode 100644 index 0000000..7504ef1 --- /dev/null +++ b/.changeset/public-bats-start.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +fix: handle completions after inline option values diff --git a/src/t.ts b/src/t.ts index ece1001..0a06457 100644 --- a/src/t.ts +++ b/src/t.ts @@ -169,11 +169,21 @@ export class RootCommand extends Command { if (arg.startsWith('-')) { i++; - const option = this.findOptionInScope(matchedCommand ?? this, arg); + const [optionName] = arg.split('='); + const hasInlineValue = arg.includes('='); + const option = this.findOptionInScope( + matchedCommand ?? this, + optionName + ); const isBoolean = option?.isBoolean ?? false; // skip the next argument if this is not a boolean option and the next arg doesn't start with - - if (!isBoolean && i < args.length && !args[i].startsWith('-')) { + if ( + !hasInlineValue && + !isBoolean && + i < args.length && + !args[i].startsWith('-') + ) { i++; } } else { @@ -211,15 +221,17 @@ export class RootCommand extends Command { if (arg.startsWith('-')) { i++; + const [optionName] = arg.split('='); + const hasInlineValue = arg.includes('='); let isBoolean = false; - const rootOption = this.findOption(this, arg); + const rootOption = this.findOption(this, optionName); if (rootOption) { isBoolean = rootOption.isBoolean ?? false; } else { // subcommand options for (const [, command] of this.commands) { - const option = this.findOption(command, arg); + const option = this.findOption(command, optionName); if (option) { isBoolean = option.isBoolean ?? false; break; @@ -228,7 +240,12 @@ export class RootCommand extends Command { } // skip the next argument if this is not a boolean option and the next arg doesn't start with - - if (!isBoolean && i < args.length && !args[i].startsWith('-')) { + if ( + !hasInlineValue && + !isBoolean && + i < args.length && + !args[i].startsWith('-') + ) { i++; } } else { @@ -280,6 +297,10 @@ export class RootCommand extends Command { // previous argument was an option, check if it expects a value if (lastPrevArg?.startsWith('-')) { + if (lastPrevArg.includes('=')) { + return false; + } + let option: Option | undefined; if (this.optionLookupMode) {