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

Support usage as plugin for tools like kubectl #2018

Merged
merged 1 commit into from
Nov 2, 2023
Merged

Commits on Sep 8, 2023

  1. Support usage as plugin for tools like kubectl

    In this case the executable is `kubectl-plugin`, but we run it as:
    
        kubectl plugin
    
    And the help text should reflect the actual usage of the command.
    
    To create a plugin, add the cobra.CommandDisplayNameAnnotation:
    
        rootCmd := &cobra.Command{
            Use: "plugin",
            Annotations: map[string]string{
                cobra.CommandDisplayNameAnnotation: "kubectl plugin",
            }
        }
    
    Internally this change modifies CommandPath() for the root command to
    return the command display name instead of the command name. This is
    used for error messages, help text generation, and completions.
    
    CommandPath() is expected to have spaces and code using it already
    handle spaces (e.g replacing with _), so hopefully this does not break
    anything.
    
    Fixes: spf13#2017
    Signed-off-by: Nir Soffer <nsoffer@redhat.com>
    nirs committed Sep 8, 2023
    Configuration menu
    Copy the full SHA
    c35d881 View commit details
    Browse the repository at this point in the history