Repository: yargs/yargs (js)

Issue:
Bash completion with Positional Arguments
- command: `exports.command = 'test <dir>';`
- exec: `node bin.js --get-yargs-completions`
- output: `test <dir>`
- then the bash completion will output  `test` and `<dir>`

[completion](https://github.com/yargs/yargs/blob/master/lib/completion.js#L59) should be `command[0].split('  ')[0]`

Pull request description:
BugFix: Exclude positional arguments from completion output
Fixes #818 + Added test

Patch:
diff --git a/lib/completion.js b/lib/completion.js
index ba23d43..1cbd796 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)
         }
       })
     }


Test patch:
diff --git a/test/completion.js b/test/completion.js
index 71cf571..eb80c30 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 <arg>', '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)