Skip to content

Commit 864242b

Browse files
authored
fix: should complete options after boolean option (#95)
1 parent 88bfb2a commit 864242b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/warm-pants-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/tab': patch
3+
---
4+
5+
fix: should complete options after boolean option

src/t.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ export class RootCommand extends Command {
261261
const [flag] = toComplete.split('=');
262262
optionName = flag;
263263
} else if (lastPrevArg?.startsWith('-')) {
264-
optionName = lastPrevArg;
264+
const option = this.findOption(command, lastPrevArg);
265+
if (option && !option.isBoolean) {
266+
optionName = lastPrevArg;
267+
}
265268
}
266269

267270
if (optionName) {

tests/cli.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ describe.each(cliTools)('cli completion tests for %s', (cliTool) => {
110110
// Should complete subcommands that start with 's' even after a boolean option
111111
expect(output).toContain('start');
112112
});
113+
114+
it('should not interfere with option completion after boolean options', async () => {
115+
const command = `${commandPrefix} dev --verbose --h`;
116+
const output = await runCommand(command);
117+
// Should complete subcommands that start with 's' even after a boolean option
118+
expect(output).toContain('--host');
119+
});
113120
});
114121

115122
describe.runIf(!shouldSkipTest)('option API overload tests', () => {

0 commit comments

Comments
 (0)