-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fixes and docs for usage as plugin #2070
Conversation
When using `CommandDisplayNameAnnotation` we want to use it instead of the command name in `--help` message or in the default help command. With current code we get the wrong text in the --help usage text: Flags: -h, --help help for kubectl-plugin And in the long description of the default help command: $ kubectl cobraplugin help -h Help provides help for any command in the application. Simply type kubectl-plugin help [path to command] for full details. The issue was hidden since the test checked only the Usage line. Fixed by extracting a displayName() function and use it when creating FlagSet and when formatting the default help flag usage and the help command long description. Enhance the TestPlugin to check all the lines including the command name.
Required for --help message and help command fixes[1] [1] spf13/cobra#2070)
Example runs using https://github.com/nirs/kubectl-cobraplugin Root command help:
Sub command help:
Help command help:
|
The plugin help text was not consistent - using `ns` in some cases and `kubectl ns` in others: $ ./kubectl-ns -h ... Usage: ns [new-namespace] [flags] Examples: # view the current namespace in your KUBECONFIG kubectl ns ... Flags: -h, --help help for ns ... With cobra 1.8.1 we can fix the issue by annotating the command so the help text matches the way we use the command. With this change we can use the executable name (kubectl-ns) as the `Use` argument, and have `kubectl ns` in the help text. Issues: - Requires Cobra release including spf13/cobra#2070 - Tested using local cobra with the require fix.
When creating a plugin without sub commands, the help text included the command name (kubectl-plugin) instead of the display name (kubectl plugin): Usage: kubectl-plugin [flags] The issue is that the usage line for this case does not use the command path but the raw `Use` string, and this case was not tested. Add a test for this case and fix UsageLine() to replace the command name with the display name. Tested using https://github.com/nirs/kubernetes/tree/sample-cli-plugin-help
Using the new CommandDisplayNameAnnotation annotation introduced in Cobra 1.8.0.
Examples run with sample-cli-plugin:
|
@jpmcb @marckhouzam did you have time to look at it? |
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.
Thank you for following-up on these issues @nirs !
LGTM
Using the new CommandDisplayNameAnnotation annotation introduced in Cobra 1.8.0.
Fixes help text issues with: