Skip to content

Commit

Permalink
Remove invocation with "kubernetes" in the help
Browse files Browse the repository at this point in the history
Plugins should use the global target.
Plugins that still use the kubernetes target but recompile with the
latest plugin-runtime library will at least no longer show the
invocation form that uses "kubernetes" in the help messages.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam committed Jun 8, 2024
1 parent 8031884 commit 605fffe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
31 changes: 19 additions & 12 deletions plugin/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,12 @@ func formatUsageHelpSection(cmd *cobra.Command, target types.Target) string {
base := indentStr + "tanzu"

if cmd.Runnable() {
// For kubernetes, k8s, global, or no target display tanzu command path without target
if target == types.TargetK8s || target == types.TargetGlobal || target == types.TargetUnknown {

if shouldPrintInvocationWithoutTarget(target) {
output.WriteString(buildInvocationString(base, useLineEx(cmd, ic)) + "\n")
}

// For non global, or no target ;display tanzu command path with target
if target != types.TargetGlobal && target != types.TargetUnknown {
if shouldPrintInvocationWithTarget(target) {
output.WriteString(buildInvocationString(base, string(target), useLineEx(cmd, ic)) + "\n")
}
}
Expand All @@ -216,13 +215,12 @@ func formatUsageHelpSection(cmd *cobra.Command, target types.Target) string {
// line between the usage for the Runnable and the one for the sub-commands
output.WriteString("\n")
}
// For kubernetes, k8s, global, or no target display tanzu command path without target
if target == types.TargetK8s || target == types.TargetGlobal || target == types.TargetUnknown {

if shouldPrintInvocationWithoutTarget(target) {
output.WriteString(buildInvocationString(base, commandPathEx(cmd, ic), "[command]") + "\n")
}

// For non global, or no target display tanzu command path with target
if target != types.TargetGlobal && target != types.TargetUnknown {
if shouldPrintInvocationWithTarget(target) {
output.WriteString(buildInvocationString(base, string(target), commandPathEx(cmd, ic), "[command]") + "\n")
}
}
Expand All @@ -244,13 +242,11 @@ func formatHelpFooter(cmd *cobra.Command, target types.Target) string {
base = "Use \"tanzu"
}

// For kubernetes, k8s, global, or no target display tanzu command path without target
if target == types.TargetK8s || target == types.TargetGlobal || target == types.TargetUnknown {
if shouldPrintInvocationWithoutTarget(target) {
footer.WriteString(buildInvocationString(base, commandPathEx(cmd, ic), `[command] --help" for more information about a command.`+"\n"))
}

// For non global, or no target display tanzu command path with target
if target != types.TargetGlobal && target != types.TargetUnknown {
if shouldPrintInvocationWithTarget(target) {
footer.WriteString(buildInvocationString(base, string(target), commandPathEx(cmd, ic), `[command] --help" for more information about a command.`+"\n"))
}

Expand Down Expand Up @@ -381,3 +377,14 @@ var TemplateFuncs = template.FuncMap{
"trimTrailingWhitespaces": component.TrimRightSpace,
"beginsWith": component.BeginsWith,
}

func shouldPrintInvocationWithoutTarget(target types.Target) bool {
// For kubernetes, k8s, global, or no target, display tanzu command path without target
return target == types.TargetK8s || target == types.TargetGlobal || target == types.TargetUnknown
}

func shouldPrintInvocationWithTarget(target types.Target) bool {
// For non global, or no target display tanzu command path with target
// Also, for the deprecated invocation using the kubernetes target, no longer display the command path with the target
return target != types.TargetGlobal && target != types.TargetUnknown && target != types.TargetK8s
}
5 changes: 2 additions & 3 deletions plugin/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestGlobalTestPluginCommandHelpText(t *testing.T) {
//
// is a known bug in cobra 1.8.0 that should be fixed in the next patch or
// minor release
//nolint:goconst
expected := `Test the CLI
Usage:
Expand Down Expand Up @@ -234,7 +235,6 @@ func TestKubernetesTestPluginCommandHelpText(t *testing.T) {
Usage:
tanzu test [command]
tanzu kubernetes test [command]
Aliases:
test, t
Expand All @@ -254,7 +254,6 @@ Additional help topics:
test plugin Plugin tests
Use "tanzu test [command] --help" for more information about a command.
Use "tanzu kubernetes test [command] --help" for more information about a command.
`
assert.Equal(t, expected, got)
}
Expand Down Expand Up @@ -351,6 +350,7 @@ func TestGlobalTestPluginFetchCommandHelpText(t *testing.T) {
assert.Nil(t, err)

got := string(<-c)
//nolint:goconst
expected := `Fetch the plugin tests
Usage:
Expand Down Expand Up @@ -466,7 +466,6 @@ func TestKubernetesTestPluginFetchCommandHelpText(t *testing.T) {
Usage:
tanzu test fetch [flags]
tanzu kubernetes test fetch [flags]
Examples:
sample example usage of the fetch command
Expand Down

0 comments on commit 605fffe

Please sign in to comment.