Skip to content

Commit

Permalink
Fix usage footer generation of mapped command
Browse files Browse the repository at this point in the history
- and some typos, linter warnings

Signed-off-by: Vui Lam <[email protected]>
  • Loading branch information
vuil committed Apr 19, 2024
1 parent a4f71d4 commit 48329bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func TestAddCommands(t *testing.T) {
Hidden: false,
SupportedContextType: []types.ContextType{types.ContextTypeTanzu},
CommandMap: []CommandMapEntry{
CommandMapEntry{
{
DestinationCommandPath: "dummy2",
},
CommandMapEntry{
{
SourceCommandPath: "delete",
DestinationCommandPath: "delete",
Description: "Delete the dummy and all the related resources",
},
CommandMapEntry{
{
SourceCommandPath: "deeper delete2",
DestinationCommandPath: "deepdel2",
Description: "Delete a dummy, much deeply",
Expand Down
5 changes: 3 additions & 2 deletions plugin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ type CommandMapEntry struct {
// to the root Command of the Tanzu CLI
DestinationCommandPath string `json:"dstPath" yaml:"dstPath"`
// By default, the command previously situated at the
// DestinationCommandPath of the Tanzu CLI, if exist, will be the one
// DestinationCommandPath of the Tanzu CLI, if one exist, will be the one
// overridden by this entry. If this mapping attempt is intended to
// override another part of the Tanzu CLI command tree, the override path should be used.
// Specified as a space-delimited path relative to the Tanzu CLI command tree.
Overrides string `json:"overrides" yaml:"overrides"`
// Required when remapping a subcommand of this plugin outside of the
// plugin's command tree (e.g. whe elevating a subcommand to a top level
// plugin's command tree (e.g. when elevating a subcommand to a top level
// command of the Tanzu CLI). This enables the CLI to provide better help
// information about the remapped command.
// Not used for plugin-level mapping. Optional for subcommand mapping in the
Expand Down
18 changes: 8 additions & 10 deletions plugin/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,20 @@ func formatHelpFooter(cmd *cobra.Command, target types.Target) string {

footer.WriteString("\n")

ic := GetInvocationContext()
base := "Use \""
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
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 {
footer.WriteString(`Use "`)
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
footer.WriteString("tanzu ")
}
footer.WriteString(cmd.CommandPath() + ` [command] --help" for more information about a command.` + "\n")
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 {
footer.WriteString(`Use "`)
if !strings.HasPrefix(cmd.CommandPath(), "tanzu ") {
footer.WriteString("tanzu ")
}
footer.WriteString(string(target) + " " + cmd.CommandPath() + ` [command] --help" for more information about a command.` + "\n")
footer.WriteString(buildInvocationString(base, string(target), commandPathEx(cmd, ic), `[command] --help" for more information about a command.`+"\n"))
}

return footer.String()
Expand Down

0 comments on commit 48329bc

Please sign in to comment.