diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 5845d0c80..439bb4136 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -31,6 +31,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" + "github.com/fatih/color" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -88,9 +89,27 @@ func NewRootCmd(version, date string, p *print.Printer) *cobra.Command { c.Flags().BoolP("help", "h", false, fmt.Sprintf("Help for %q", c.CommandPath())) }) + beautifyUsageTemplate(cmd) + return cmd } +func beautifyUsageTemplate(cmd *cobra.Command) { + cobra.AddTemplateFunc("WhiteBold", color.New(color.FgHiWhite, color.Bold).SprintFunc()) + usageTemplate := cmd.UsageTemplate() + usageTemplate = strings.NewReplacer( + `Usage:`, `{{WhiteBold "USAGE"}}`, + `Examples:`, `{{WhiteBold "EXAMPLES"}}`, + `Aliases:`, `{{WhiteBold "ALIASES"}}`, + `Available Commands:`, `{{WhiteBold "AVAILABLE COMMANDS"}}`, + `Additional Commands:`, `{{WhiteBold "ADDITIONAL COMMANDS"}}`, + `Global Flags:`, `{{WhiteBold "GLOBAL FLAGS"}}`, + `Flags:`, `{{WhiteBold "FLAGS"}}`, + `Additional help topics:`, `{{WhiteBold "ADDITIONAL HELP TOPICS"}}`, + ).Replace(usageTemplate) + cmd.SetUsageTemplate(usageTemplate) +} + func configureFlags(cmd *cobra.Command) error { cmd.Flags().BoolP("version", "v", false, `Show "stackit" version`)