Skip to content

Commit

Permalink
feat: allow completionCommand to be set via showCompletionScript (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronhunter authored and bcoe committed Jul 30, 2019
1 parent 07a5554 commit 5562853
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions test/completion.js
Expand Up @@ -158,6 +158,13 @@ describe('Completion', () => {

r.logs[0].should.match(/\.\/test.js --get-yargs-completions/)
})

it('allows $0 and cmd to be set', () => {
const r = checkUsage(() => yargs([])
.showCompletionScript('/path/to/my/app', 'show-completions-script'))

r.logs[0].should.match(/Installation: \/path\/to\/my\/app show-completions-script/)
})
})

describe('completion()', () => {
Expand Down
7 changes: 4 additions & 3 deletions yargs.js
Expand Up @@ -908,7 +908,7 @@ function Yargs (processArgs, cwd, parentRequire) {
}

// register the completion command.
completionCommand = cmd || 'completion'
completionCommand = cmd || completionCommand || 'completion'
if (!desc && desc !== false) {
desc = 'generate completion script'
}
Expand All @@ -920,9 +920,10 @@ function Yargs (processArgs, cwd, parentRequire) {
return self
}

self.showCompletionScript = function ($0) {
argsert('[string]', [$0], arguments.length)
self.showCompletionScript = function ($0, cmd) {
argsert('[string] [string]', [$0, cmd], arguments.length)
$0 = $0 || self.$0
completionCommand = cmd || completionCommand || 'completion'
_logger.log(completion.generateCompletionScript($0, completionCommand))
return self
}
Expand Down

0 comments on commit 5562853

Please sign in to comment.