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
Autocomplete: subcommands are run while in autocompletion mode #272
Comments
Anyone had the same issue? |
I ran into this bug. It happens when you pass arguments like this In this case I think the best solution would be to parse |
Indeed, this does seem like a bug. I'll try to find some time to address this, but I'm happy to review any pull requests to push this along. |
This could be mitigated slightly by changing the script to insert |
Based on @tianon's suggestion something like this could be done. It appears to work for regular Commands with bash completion, I haven't used for SubCommands. if [ $COMP_CWORD -eq 1 ]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
else
opts=$(${COMP_WORDS[@]:0:2} --generate-bash-completion ${COMP_WORDS[@]:2:$COMP_CWORD} )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
Given that this is from last year, I think I'm comfortable closing it 🙂 feel free to re-open / open a new issue / comment in support if there's still interest here! |
It appears that when I do:
my client tries to run -n or whatever the last arg is, and ends up showing my app's help.
Sometimes when "-n" is a correct command, it's executed and showing in the argument selection while it should not.
I decided to take a look at cli functions:
-> codegangsta/cli/help.go
And I noticed that c.Bool(BashCompletionFlag.Name) was false sometimes, while I am pressing tab and not running the program.
I replaced this code by :
And also here :
https://github.com/codegangsta/cli/blob/master/command.go#L53-L129
I moved the context declaration and the checkCommandCompletions call, next to the set.SetOutput call like this :
That way, the cli doesn't call command or help ( if the command doesn't exist ) anymore if bash completion is enabled.
It's working very well for me but I'm sure there's a better way to do it.
Thanks in advance,
The text was updated successfully, but these errors were encountered: