Skip to content

Commit 180cd3e

Browse files
committed
fix: Update cli usage template for cobra feature parity
Fixes #1423 Related #1233, #1403
1 parent 7bb7c6c commit 180cd3e

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

cli/root.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,32 @@ func usageTemplate() string {
183183
// more visually appealing.
184184
header := cliui.Styles.Placeholder
185185

186-
return `{{if .HasExample}}` + header.Render("Get Started:") + `
187-
{{.Example}}
186+
return header.Render("Usage:") + `{{if .Runnable}}
187+
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
188+
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
188189
189-
{{end}}{{if .HasAvailableLocalFlags}}` + header.Render("Flags:") + `
190-
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableSubCommands}}
190+
` + header.Render("Aliases:") + `
191+
{{.NameAndAliases}}{{end}}{{if .HasExample}}
191192
192-
` + header.Render("Commands:") + `{{range .Commands}}{{if and .IsAvailableCommand (eq (len .Annotations) 0)}}
193-
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if not .HasParent }}
193+
` + header.Render("Get Started:") + `
194+
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
194195
195-
` + header.Render("Workspace Commands:") + `{{range .Commands}}{{if and .IsAvailableCommand (ne (index .Annotations "workspaces") "")}}
196-
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}
196+
` + header.Render("Commands:") + `{{range .Commands}}{{if (or (and .IsAvailableCommand (eq (len .Annotations) 0)) (eq .Name "help"))}}
197+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if and (not .HasParent) .HasAvailableSubCommands}}
197198
198-
Use "{{.CommandPath}} [command] --help" for more information about a command.
199+
` + header.Render("Workspace Commands:") + `{{range .Commands}}{{if (and .IsAvailableCommand (ne (index .Annotations "workspaces") ""))}}
200+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
201+
202+
` + header.Render("Flags:") + `
203+
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
204+
205+
` + header.Render("Global Flags:") + `
206+
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
207+
208+
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
209+
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
210+
211+
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
199212
`
200213
}
201214

0 commit comments

Comments
 (0)