diff --git a/.changeset/brave-roots-count.md b/.changeset/brave-roots-count.md new file mode 100644 index 0000000..7322a13 --- /dev/null +++ b/.changeset/brave-roots-count.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +fix: stop completing a root command argument again after it has been given diff --git a/src/t.ts b/src/t.ts index b22cd9c..5126abd 100644 --- a/src/t.ts +++ b/src/t.ts @@ -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()); diff --git a/tests/cli.test.ts b/tests/cli.test.ts index 742a509..e46c43b 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -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', () => {