diff --git a/internal/ansi/ansi.go b/internal/ansi/ansi.go index a03e0f35b..091ba1ac3 100644 --- a/internal/ansi/ansi.go +++ b/internal/ansi/ansi.go @@ -88,6 +88,12 @@ func Red(text string) string { return color.Sprintf(color.Red(text)) } +// BrightRed returns text colored bright red +func BrightRed(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.BrightRed(text)) +} + // Green returns text colored green func Green(text string) string { color := Color(os.Stdout) @@ -100,6 +106,12 @@ func Yellow(text string) string { return color.Sprintf(color.Yellow(text)) } +// BrightYellow returns text colored bright yellow +func BrightYellow(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.BrightYellow(text)) +} + // Blue returns text colored blue func Blue(text string) string { color := Color(os.Stdout) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 2bfc5050e..550a4c612 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -79,6 +79,7 @@ type cli struct { format string force bool noInput bool + noColor bool // config state management. initOnce sync.Once diff --git a/internal/cli/logs.go b/internal/cli/logs.go index fdcee8755..ba7efd0ff 100644 --- a/internal/cli/logs.go +++ b/internal/cli/logs.go @@ -24,12 +24,6 @@ var ( ShortForm: "n", Help: "Number of log entries to show.", } - - logsNoColor = Flag{ - Name: "Disable Color", - LongForm: "no-color", - Help: "Disable colored log output.", - } ) func logsCmd(cli *cli) *cobra.Command { @@ -50,7 +44,6 @@ func listLogsCmd(cli *cli) *cobra.Command { var inputs struct { ClientID string Num int - NoColor bool } cmd := &cobra.Command{ @@ -88,14 +81,13 @@ auth0 logs ls -n 100`, cli.api.ActionExecution, time.Second, ) - cli.renderer.LogList(list, logsCh, actionExecutionAPI, inputs.NoColor, !cli.debug) + cli.renderer.LogList(list, logsCh, actionExecutionAPI, !cli.debug) return nil }, } logsClientID.RegisterString(cmd, &inputs.ClientID, "") logsNum.RegisterInt(cmd, &inputs.Num, 100) - logsNoColor.RegisterBool(cmd, &inputs.NoColor, false) return cmd } @@ -103,7 +95,6 @@ func tailLogsCmd(cli *cli) *cobra.Command { var inputs struct { ClientID string Num int - NoColor bool } cmd := &cobra.Command{ @@ -181,14 +172,13 @@ auth0 logs tail -n 100`, cli.api.ActionExecution, time.Second, ) - cli.renderer.LogList(list, logsCh, actionExecutionAPI, inputs.NoColor, !cli.debug) + cli.renderer.LogList(list, logsCh, actionExecutionAPI, !cli.debug) return nil }, } logsClientID.RegisterString(cmd, &inputs.ClientID, "") logsNum.RegisterInt(cmd, &inputs.Num, 100) - logsNoColor.RegisterBool(cmd, &inputs.NoColor, false) return cmd } diff --git a/internal/cli/root.go b/internal/cli/root.go index 273081fa8..8e5ef01d9 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -59,6 +59,8 @@ func Execute() { return nil } + ansi.DisableColors = cli.noColor + // Initialize everything once. Later callers can then // freely assume that config is fully primed and ready // to go. @@ -82,6 +84,8 @@ func Execute() { rootCmd.PersistentFlags().BoolVar(&cli.noInput, "no-input", false, "Disable interactivity.") + rootCmd.PersistentFlags().BoolVar(&cli.noColor, + "no-color", false, "Disable colors.") // order of the comamnds here matters // so add new commands in a place that reflect its relevance or relation with other commands: rootCmd.AddCommand(loginCmd(cli)) diff --git a/internal/display/display.go b/internal/display/display.go index 0ecbab316..b8352959b 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -10,7 +10,6 @@ import ( "github.com/auth0/auth0-cli/internal/ansi" "github.com/charmbracelet/glamour" - "github.com/logrusorgru/aurora" "github.com/olekukonko/tablewriter" ) @@ -45,17 +44,17 @@ func (r *Renderer) Newline() { } func (r *Renderer) Infof(format string, a ...interface{}) { - fmt.Fprint(r.MessageWriter, aurora.Green(" ▸ ")) + fmt.Fprint(r.MessageWriter, ansi.Green(" ▸ ")) fmt.Fprintf(r.MessageWriter, format+"\n", a...) } func (r *Renderer) Warnf(format string, a ...interface{}) { - fmt.Fprint(r.MessageWriter, aurora.Yellow(" ▸ ")) + fmt.Fprint(r.MessageWriter, ansi.Yellow(" ▸ ")) fmt.Fprintf(r.MessageWriter, format+"\n", a...) } func (r *Renderer) Errorf(format string, a ...interface{}) { - fmt.Fprint(r.MessageWriter, aurora.BrightRed(" ▸ ")) + fmt.Fprint(r.MessageWriter, ansi.BrightRed(" ▸ ")) fmt.Fprintf(r.MessageWriter, format+"\n", a...) } diff --git a/internal/display/logs.go b/internal/display/logs.go index 3809893be..26d861ef6 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -6,7 +6,6 @@ import ( "github.com/auth0/auth0-cli/internal/ansi" "github.com/auth0/auth0-cli/internal/auth0" - "github.com/logrusorgru/aurora" "gopkg.in/auth0.v5/management" "gopkg.in/yaml.v2" @@ -26,8 +25,7 @@ type logCategory int var _ View = &logView{} type logView struct { - silent bool - noColor bool + silent bool *management.Log ActionExecutionAPI auth0.ActionExecutionAPI @@ -130,23 +128,21 @@ func (v *logView) typeDesc() (typ, desc string) { desc = fmt.Sprintf("%s %s", desc, auth0.StringValue(v.Description)) - if !v.noColor { - switch v.category() { - case logCategorySuccess: - typ = aurora.Green(typ).String() - case logCategoryFailure: - typ = aurora.BrightRed(typ).String() - case logCategoryWarning: - typ = aurora.BrightYellow(typ).String() - default: - typ = ansi.Faint(typ) - } + switch v.category() { + case logCategorySuccess: + typ = ansi.Green(typ) + case logCategoryFailure: + typ = ansi.BrightRed(typ) + case logCategoryWarning: + typ = ansi.BrightYellow(typ) + default: + typ = ansi.Faint(typ) } return typ, desc } -func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, api auth0.ActionExecutionAPI, noColor, silent bool) { +func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, api auth0.ActionExecutionAPI, silent bool) { resource := "logs" r.Heading(resource) @@ -159,7 +155,7 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, var res []View for _, l := range logs { - res = append(res, &logView{Log: l, ActionExecutionAPI: api, silent: silent, noColor: noColor}) + res = append(res, &logView{Log: l, ActionExecutionAPI: api, silent: silent}) } var viewChan chan View @@ -172,7 +168,7 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, for list := range ch { for _, l := range list { - viewChan <- &logView{Log: l, ActionExecutionAPI: api, silent: silent, noColor: noColor} + viewChan <- &logView{Log: l, ActionExecutionAPI: api, silent: silent} } } }()