Skip to content
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

Merged
merged 3 commits into from
Dec 18, 2023
Merged

Fixes and docs for usage as plugin #2070

merged 3 commits into from
Dec 18, 2023

Commits on Nov 12, 2023

  1. Fix help text for plugins

    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.
    nirs committed Nov 12, 2023
    Configuration menu
    Copy the full SHA
    87f8a10 View commit details
    Browse the repository at this point in the history
  2. Fix help text for runnable plugin command

    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
    nirs committed Nov 12, 2023
    Configuration menu
    Copy the full SHA
    e368063 View commit details
    Browse the repository at this point in the history
  3. Document how to create a plugin

    Using the new CommandDisplayNameAnnotation annotation introduced in
    Cobra 1.8.0.
    nirs committed Nov 12, 2023
    Configuration menu
    Copy the full SHA
    e00551d View commit details
    Browse the repository at this point in the history