Skip to content

Commit 3eebc87

Browse files
authored
Improve config set command help (#256)
* Improve command help * Fix typo
1 parent 5a8aa14 commit 3eebc87

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

internal/cmd/config/set/set.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ func NewCmd(p *print.Printer) *cobra.Command {
8888
},
8989
}
9090
configureFlags(cmd)
91+
cmd.SetHelpTemplate( // Slightly modified help template to merge the command level Flags and Global Flags in a single section
92+
`Usage:{{if .Runnable}}
93+
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
94+
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
95+
96+
Aliases:
97+
{{.NameAndAliases}}{{end}}{{if .HasExample}}
98+
99+
Examples:
100+
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}}
101+
102+
Available Commands:{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
103+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}}
104+
105+
{{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}}
106+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}}
107+
108+
Additional Commands:{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}}
109+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
110+
111+
Flags:
112+
{{.Flags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
113+
114+
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
115+
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
116+
117+
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
118+
`)
91119
return cmd
92120
}
93121

0 commit comments

Comments
 (0)