Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getCompletion() no longer working for options #1495

Merged
merged 2 commits into from Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/completion.js
Expand Up @@ -8,6 +8,11 @@ module.exports = function completion (yargs, usage, command) {
completionKey: 'get-yargs-completions'
}

let aliases
self.setParsed = function setParsed (parsed) {
aliases = parsed.aliases
}

const zshShell = (process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1) ||
(process.env.ZSH_NAME && process.env.ZSH_NAME.indexOf('zsh') !== -1)
// get a list of completion commands.
Expand All @@ -16,7 +21,6 @@ module.exports = function completion (yargs, usage, command) {
const completions = []
const current = args.length ? args[args.length - 1] : ''
const argv = yargs.parse(args, true)
const aliases = yargs.parsed.aliases
const parentCommands = yargs.getContext().commands

// a custom completion function can be provided
Expand Down
17 changes: 16 additions & 1 deletion test/completion.js
Expand Up @@ -358,10 +358,25 @@ describe('Completion', () => {
})
})
})

r.logs.should.include('apple')
r.logs.should.include('foo')
})
it('returns default completion to callback for options', () => {
process.env.SHELL = '/bin/bash'
const r = checkUsage(() => {
yargs()
.option('apple')
.option('foo')
.completion()
.getCompletion(['$0', '-'], (completions) => {
;(completions || []).forEach((completion) => {
console.log(completion)
})
})
})
r.logs.should.include('--apple')
r.logs.should.include('--foo')
})
})
})

Expand Down
1 change: 1 addition & 0 deletions yargs.js
Expand Up @@ -581,6 +581,7 @@ function Yargs (processArgs, cwd, parentRequire) {
if (parseFn) exitProcess = false

const parsed = self._parseArgs(args, shortCircuit)
completion.setParsed(self.parsed)
if (parseFn) parseFn(exitError, parsed, output)
unfreeze()

Expand Down