diff --git a/command.go b/command.go index 2df6975f..a8bda03b 100644 --- a/command.go +++ b/command.go @@ -1216,7 +1216,7 @@ func (c *Command) InitDefaultVersionFlag() { if c.Name() == "" { usage += "this command" } else { - usage += c.Name() + usage += c.displayName() } if c.Flags().ShorthandLookup("v") == nil { c.Flags().BoolP("version", "v", false, usage) diff --git a/command_test.go b/command_test.go index 9ce7a529..caf8c121 100644 --- a/command_test.go +++ b/command_test.go @@ -371,8 +371,9 @@ func TestAliasPrefixMatching(t *testing.T) { // text should reflect the way we run the command. func TestPlugin(t *testing.T) { cmd := &Command{ - Use: "kubectl-plugin", - Args: NoArgs, + Use: "kubectl-plugin", + Version: "1.0.0", + Args: NoArgs, Annotations: map[string]string{ CommandDisplayNameAnnotation: "kubectl plugin", }, @@ -386,13 +387,15 @@ func TestPlugin(t *testing.T) { checkStringContains(t, cmdHelp, "kubectl plugin [flags]") checkStringContains(t, cmdHelp, "help for kubectl plugin") + checkStringContains(t, cmdHelp, "version for kubectl plugin") } // TestPlugin checks usage as plugin with sub commands. func TestPluginWithSubCommands(t *testing.T) { rootCmd := &Command{ - Use: "kubectl-plugin", - Args: NoArgs, + Use: "kubectl-plugin", + Version: "1.0.0", + Args: NoArgs, Annotations: map[string]string{ CommandDisplayNameAnnotation: "kubectl plugin", }, @@ -408,6 +411,7 @@ func TestPluginWithSubCommands(t *testing.T) { checkStringContains(t, rootHelp, "kubectl plugin [command]") checkStringContains(t, rootHelp, "help for kubectl plugin") + checkStringContains(t, rootHelp, "version for kubectl plugin") checkStringContains(t, rootHelp, "kubectl plugin [command] --help") childHelp, err := executeCommand(rootCmd, "sub", "-h")