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
Allow completionCommand to be set via showCompletionScript #1385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this bug cropped up if you manually called showCompletionScript
to get yargs to output the completion script, rather than passing an argument to generate a completion command?
I'm curious, what's your use case?
@@ -907,7 +907,7 @@ function Yargs (processArgs, cwd, parentRequire) { | |||
} | |||
|
|||
// register the completion command. | |||
completionCommand = cmd || 'completion' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly confused, wouldn't this have defaulted to completion
? where was the null
value coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our use-case is that we want to set
|
@cameronhunter excited to have the contributions, thank you 👍 will work on getting a release out soon. |
@cameronhunter please try |
Thanks for merging, though I think this PR isn't acting as expected 😓 – I'm seeing the script being logged twice. I think it's due to me setting I'm trying to piece together a test-case but I think the correct fix is not to set |
Problem
When using
showCompletionScript
the variablecompletionCommand
isnull
resulting in a bad installation instruction. For example:yargs.showCompletionScript('/usr/local/bin/my-app');
Notice that
null
is printed for the command.It's possible to set the
completionCommand
variable by callingyargs.completion()
but this will also log the completion script resulting in two scripts being logged when used in conjunction withshowCompletionScript
:yargs.completion().showCompletionScript('/usr/local/bin/my-app');
In this case the first completion script output is correct but the second one is incorrect.
Fix
Add a second parameter to
showCompletionScript
that allows the developer to set the completion command variable.yargs.showCompletionScript('/usr/local/bin/my-app', 'completion');
It will default to "completion" in the same way that
completion()
does.