diff --git a/.changeset/warm-pants-roll.md b/.changeset/warm-pants-roll.md new file mode 100644 index 0000000..1431280 --- /dev/null +++ b/.changeset/warm-pants-roll.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +fix: should complete options after boolean option diff --git a/src/t.ts b/src/t.ts index 601c7ff..8dabcaa 100644 --- a/src/t.ts +++ b/src/t.ts @@ -261,7 +261,10 @@ export class RootCommand extends Command { const [flag] = toComplete.split('='); optionName = flag; } else if (lastPrevArg?.startsWith('-')) { - optionName = lastPrevArg; + const option = this.findOption(command, lastPrevArg); + if (option && !option.isBoolean) { + optionName = lastPrevArg; + } } if (optionName) { diff --git a/tests/cli.test.ts b/tests/cli.test.ts index 20e5a00..0822ee1 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -110,6 +110,13 @@ describe.each(cliTools)('cli completion tests for %s', (cliTool) => { // Should complete subcommands that start with 's' even after a boolean option expect(output).toContain('start'); }); + + it('should not interfere with option completion after boolean options', async () => { + const command = `${commandPrefix} dev --verbose --h`; + const output = await runCommand(command); + // Should complete subcommands that start with 's' even after a boolean option + expect(output).toContain('--host'); + }); }); describe.runIf(!shouldSkipTest)('option API overload tests', () => {