Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-roots-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bomb.sh/tab': patch
---

fix: stop completing a root command argument again after it has been given
4 changes: 2 additions & 2 deletions src/t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ export class RootCommand extends Command {
private handlePositionalCompletion(command: Command, previousArgs: string[]) {
// Strip options so flags don't inflate the positional index
const strippedArgs = this.stripOptions(previousArgs);
// current argument position (subtract command name)
const commandParts = command.value.split(' ').length;
// current argument position (subtract command name; the root has none)
const commandParts = command === this ? 0 : command.value.split(' ').length;
const currentArgIndex = Math.max(0, strippedArgs.length - commandParts);
const argumentEntries = Array.from(command.arguments.entries());

Expand Down
6 changes: 6 additions & 0 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ describe.each(cliTools)('cli completion tests for %s', (cliTool) => {
const output = await runCommand(command);
expect(output).toMatchSnapshot();
});

it('should not complete root command project argument again after it is given', async () => {
const command = `${commandPrefix} my-app ""`;
const output = await runCommand(command);
expect(output).toBe(':4\n');
});
});

describe('root command option tests', () => {
Expand Down