Don't disable flag parsing on the root command #600
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first commit of this PR is #594 for cobra 1.8.0
What this PR does / why we need it
This PR stops disabling flag parsing on the root CLI command to fix a small bug when updating to cobra 1.8.0.
I purposely kept this PR separate from #594 because even if we don't move to cobra 1.8.0, there is no reason for the CLI to disable flag parsing on its root command, as is explained below.
By disabling flag parsing on the root command, we tell Cobra not to parse flags when running the root command. Since there are are currently no flags on the root command this is not a problem. Furthermore, even with say, a global flag on the root command, this situation would still not be a problem because the root command is not actually runnable itself (no
Run
function), so flags would not be executed on the root command itself, but instead theDisableFlagParsing
field would be read from the executable sub-command used.However, there is an issue with not parsing flags on the root which is that it prevents Cobra's shell completion logic to complete the
--help/-h
flags on the root command. This is because all flag name completion becomes the responsibility of the program itself, and the program did not itself define--help/-h
. This happens starting with Cobra v1.8.0.We can see this by running
tanzu __complete -
and noticing the--help/-h
flags are not suggested when using cobra 1.8.0.The reason flag parsing was disabled on the root seems to be to allow plugins to handle their own flags. However, this is already done by each individual plugin sub-command created by
GetCmdForPlugin()
which does disable flag parsing already. There is therefore no reason to disable flag parsing on the root command.Which issue(s) this PR fixes
Fixes # N/A
Describe testing done for PR
Release note
Additional information
Special notes for your reviewer