Are you asking about colorizing the output of the commands you write in your own apps, or are you asking about colorizing the output of the cobra command ( https://github.com/spf13/cobra/blob/master/cobra/README.md ) ?
My own
AFAIK, there's nothing built in to Cobra for colorizing the output. You can use a library like https://github.com/fatih/color in your own commands, though, to colorize the output you control. You can also use a library to colorize the output of the Help and Usage commands by writing your own functions (see Defining your own help and Defining your own usage in the README. Hope this helps.
In help command?
Yes -- go here https://github.com/spf13/cobra#help-command and read the section Defining your own help for how you can write your own help command. Since it's your own, you can colorize however you want.
I had some success with this (via https://github.com/fatih/color) by:
rootCmd.SetOutput(color.Output) cobra.AddTemplateFunc("StyleHeading", color.New(color.FgGreen).SprintFunc())
usageTemplate := rootCmd.UsageTemplate()
usageTemplate = strings.NewReplacer(
`Usage:`, `{{StyleHeading "Usage:"}}`,
`Aliases:`, `{{StyleHeading "Aliases:"}}`,
`Available Commands:`, `{{StyleHeading "Available Commands:"}}`,
`Global Flags:`, `{{StyleHeading "Global Flags:"}}`,
// The following one steps on "Global Flags:"
// `Flags:`, `{{StyleHeading "Flags:"}}`,
).Replace(usageTemplate)
re := regexp.MustCompile(`(?m)^Flags:\s*$`)
usageTemplate = re.ReplaceAllLiteralString(usageTemplate, `{{StyleHeading "Flags:"}}`)
rootCmd.SetUsageTemplate(usageTemplate)
This issue is being marked as stale due to a long period of inactivity
Most helpful comment
I had some success with this (via https://github.com/fatih/color) by:
rootCmd.SetOutput(color.Output)