Skip to content

Commit c8b12e5

Browse files
committed
Fix usage footer generation of mapped command
- and some typos, linter warnings Signed-off-by: Vui Lam <[email protected]>
1 parent e882384 commit c8b12e5

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

plugin/plugin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ func TestAddCommands(t *testing.T) {
7272
Hidden: false,
7373
SupportedContextType: []types.ContextType{types.ContextTypeTanzu},
7474
CommandMap: []CommandMapEntry{
75-
CommandMapEntry{
75+
{
7676
DestinationCommandPath: "dummy2",
7777
},
78-
CommandMapEntry{
78+
{
7979
SourceCommandPath: "delete",
8080
DestinationCommandPath: "delete",
8181
Description: "Delete the dummy and all the related resources",
8282
},
83-
CommandMapEntry{
83+
{
8484
SourceCommandPath: "deeper delete2",
8585
DestinationCommandPath: "deepdel2",
8686
Description: "Delete a dummy, much deeply",

plugin/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ type CommandMapEntry struct {
6565
// to the root Command of the Tanzu CLI
6666
DestinationCommandPath string `json:"dstPath" yaml:"dstPath"`
6767
// By default, the command previously situated at the
68-
// DestinationCommandPath of the Tanzu CLI, if exist, will be the one
68+
// DestinationCommandPath of the Tanzu CLI, if one exist, will be the one
6969
// overridden by this entry. If this mapping attempt is intended to
7070
// override another part of the Tanzu CLI command tree, the override path should be used.
71+
// Specified as a space-delimited path relative to the Tanzu CLI command tree.
7172
Overrides string `json:"overrides" yaml:"overrides"`
7273
// Required when remapping a subcommand of this plugin outside of the
73-
// plugin's command tree (e.g. whe elevating a subcommand to a top level
74+
// plugin's command tree (e.g. when elevating a subcommand to a top level
7475
// command of the Tanzu CLI). This enables the CLI to provide better help
7576
// information about the remapped command.
7677
// Not used for plugin-level mapping. Optional for subcommand mapping in the

plugin/usage.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,20 @@ func formatHelpFooter(cmd *cobra.Command, target types.Target) string {
142142

143143
footer.WriteString("\n")
144144

145+
ic := GetInvocationContext()
146+
base := "Use \""
147+
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
148+
base = "Use \"tanzu"
149+
}
150+
145151
// For kubernetes, k8s, global, or no target display tanzu command path without target
146152
if target == types.TargetK8s || target == types.TargetGlobal || target == types.TargetUnknown {
147-
footer.WriteString(`Use "`)
148-
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
149-
footer.WriteString("tanzu ")
150-
}
151-
footer.WriteString(cmd.CommandPath() + ` [command] --help" for more information about a command.` + "\n")
153+
footer.WriteString(buildInvocationString(base, commandPathEx(cmd, ic), `[command] --help" for more information about a command.`+"\n"))
152154
}
153155

154156
// For non global, or no target display tanzu command path with target
155157
if target != types.TargetGlobal && target != types.TargetUnknown {
156-
footer.WriteString(`Use "`)
157-
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
158-
footer.WriteString("tanzu ")
159-
}
160-
footer.WriteString(string(target) + " " + cmd.CommandPath() + ` [command] --help" for more information about a command.` + "\n")
158+
footer.WriteString(buildInvocationString(base, string(target), commandPathEx(cmd, ic), `[command] --help" for more information about a command.`+"\n"))
161159
}
162160

163161
return footer.String()

0 commit comments

Comments
 (0)