Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/util/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Command struct {
Subcommands []*Command
UsageFunc func(*Command) error
HelpFunc func(*Command)
GroupUsageTree bool
cobraCmd *cobra.Command
isSpaceSeparated bool
}
Expand Down Expand Up @@ -107,13 +108,19 @@ func (c *Command) defaultUsageFunc(*Command) error {
// TODO :: Seems like Usage & Help have the same use for us right now. (Perhaps just for default)
tmplName := template.DefaultTemplate
templateToExecute := template.DefaultUsageTemplate
if c.GroupUsageTree {
templateToExecute = template.DefaultUsageTemplateGrouped
}
return template.TryExecuteTemplate(tmplName, template.DefaultTemplate, templateToExecute, template.DefaultTemplateFuncs, c)
}

// defaultHelpFunc is the Help function that will be called if none is provided
func (c *Command) defaultHelpFunc(*Command) {
tmplName := template.DefaultTemplate
templateToExecute := template.DefaultHelpTemplate
if c.GroupUsageTree {
templateToExecute = template.DefaultHelpTemplateGrouped
}
err := template.TryExecuteTemplate(tmplName, template.DefaultTemplate, templateToExecute, template.DefaultTemplateFuncs, c)
if err != nil {
log.Fatalf(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/cli/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ Type {{.CommandPathBinary}}{{.CommandSeparator}}{{if .HasSubcommands}}{{ colored
{{define "TemplateBody"}}{{template "Flags" .}}{{ $namePadding := 35 }}
{{if .HasSubcommands}}
{{ colored "Subcommands: " "white" }}{{range .AllSubcommands}}
{{ colored (rpad .CommandPathBinary $namePadding) "blue" }} {{ colored .Short "gray" }}{{end}}
{{ colored (rpad .CommandPathBinary $namePadding) "blue" }}{{.Short}}{{end}}
{{end}}{{end}}

{{define "TemplateGroupedBody"}}{{template "Flags" .}}{{ $namePadding := 35 }}
{{if .HasSubcommands}}
{{ colored "Subcommands: " "white" }}
{{range .SubcommandsByGroup}}
{{ colored .GroupName "blue" }}: {{range .Commands}}
{{ colored (rpad .Name $namePadding) "none" }} {{colored .Short "gray"}}{{end}}
{{ colored (rpad .Name $namePadding) "none" }}{{.Short}}{{end}}
{{end}}{{end}}{{end}}

{{define "HelpTemplate"}}{{template "HeaderHelp" .}}{{template "TemplateBody" .}}{{end}}
Expand Down