bug report: shell completion doesn't work with sub-commands v3-alpha4
yogeshlonkar opened this issue · 2 comments
yogeshlonkar commented
Checklist
- Are you running the latest v3 release? The list of releases is here.
-
Did you check the manual for your release? The v3 manual is here.Could not find the manual, link points to 404 - Did you perform a search about this feature? Here's the GitHub guide about searching.
What problem does this solve?
If fixed, shell completion of sub-commands should work same as v2. For example:
mycli sub1 --generate-shell-completion
Instead of calling/ completing sub1
command the cli executes the action of sub1
.
The issue is here https://github.com/urfave/cli/blob/v3.0.0-alpha4/help.go#L448-L455.
--generate-shell-completion
is popped from arguments slice whencheckShellCompleteFlag
is run formycli
- In next recursive execution of
Run
forsub1
functioncheckShellCompleteFlag
returns false as there is no--generate-shell-completion
Solution description
- A separate recursive function is needed to find the last sub-command in chain.
- If argument slice contains
--generate-shell-completion
the the last sub-command directly should be invoked for completion as it doesn't need chaining - Else
Run
should continue with existing steps
If the solution correct, I will try to provide a PR for this
dearchap commented
@yogeshlonkar This issue is present only in v3. If you look at v2 the shellComplete flag is set in context which is used to check later on. If you can add the flag back into context that would be great
dearchap commented
@yogeshlonkar try this fix and see if it helps