diff --git a/lib/completion.js b/lib/completion.js index ba23d4381..1cbd79653 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -55,9 +55,10 @@ module.exports = function completion (yargs, usage, command) { } if (!current.match(/^-/)) { - usage.getCommands().forEach((command) => { - if (args.indexOf(command[0]) === -1) { - completions.push(command[0]) + usage.getCommands().forEach((usageCommand) => { + const commandName = command.parseCommand(usageCommand[0]).cmd + if (args.indexOf(commandName) === -1) { + completions.push(commandName) } }) } diff --git a/test/completion.js b/test/completion.js index 71cf571d8..eb80c3055 100644 --- a/test/completion.js +++ b/test/completion.js @@ -121,6 +121,20 @@ describe('Completion', () => { r.logs.should.include('cmd1') }) + it('does not include possitional arguments', function () { + var r = checkUsage(function () { + return yargs(['./completion', '--get-yargs-completions', 'cmd']) + .command('cmd1 [arg]', 'first command') + .command('cmd2 ', 'second command') + .completion('completion', false) + .argv + }) + + r.logs.should.have.length(2) + r.logs.should.include('cmd1') + r.logs.should.include('cmd2') + }) + it('works if command has no options', () => { const r = checkUsage(() => yargs(['./completion', '--get-yargs-completions', 'foo', '--b']) .help(false)