Skip to content

Commit

Permalink
Fix indentation in help of leaf commands (#612)
Browse files Browse the repository at this point in the history
In the help output, the usage line of leaf commands was not indented
as non-leaf commands.

Before this commit:
```
~/bin/tanzu.v1.0.0 context list -h
List contexts

Usage:
tanzu context list [flags]
[...]
```

After the commit:
```
$  tz context list -h
List contexts

Usage:
  tanzu context list [flags]
[...]
```

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam authored Dec 15, 2023
1 parent e9afe32 commit 85ea46d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (u *MainUsage) GenerateDescriptor(c *cobra.Command, w io.Writer) error {
return nil
}

// Template returns the template for the main usage.
// Template returns the template for the root cmd help as well
// as for the two target commands ('kubernetes' and 'mission-control').
// Those three commands use this template because they use command groups
// for their help text.
func (u *MainUsage) Template() string {
return `{{ bold "Usage:" }}
{{.Command.CommandPath}} [command]{{if gt (len .Aliases) 0}}
Expand All @@ -90,7 +93,7 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.
`
}

// SubCmdUsageFunc is the usage func for a plugin.
// SubCmdUsageFunc is the usage func for all core sub-commands.
var SubCmdUsageFunc = func(c *cobra.Command) error {
t, err := template.New("usage").Funcs(TemplateFuncs).Parse(SubCmdTemplate)
if err != nil {
Expand All @@ -99,9 +102,9 @@ var SubCmdUsageFunc = func(c *cobra.Command) error {
return t.Execute(os.Stdout, c)
}

// SubCmdTemplate is the template for plugin commands.
// SubCmdTemplate is the template for all core sub-commands.
const SubCmdTemplate = `{{ bold "Usage:" }}{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
{{ bold "Aliases:" }}
Expand Down

0 comments on commit 85ea46d

Please sign in to comment.