diff --git a/internal/ansi/ansi.go b/internal/ansi/ansi.go index e8b456142..a03e0f35b 100644 --- a/internal/ansi/ansi.go +++ b/internal/ansi/ansi.go @@ -82,6 +82,42 @@ func Italic(text string) string { return color.Sprintf(color.Italic(text)) } +// Red returns text colored red +func Red(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.Red(text)) +} + +// Green returns text colored green +func Green(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.Green(text)) +} + +// Yellow returns text colored yellow +func Yellow(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.Yellow(text)) +} + +// Blue returns text colored blue +func Blue(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.Blue(text)) +} + +// Magenta returns text colored magenta +func Magenta(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.Magenta(text)) +} + +// Cyan returns text colored cyan +func Cyan(text string) string { + color := Color(os.Stdout) + return color.Sprintf(color.BrightCyan(text)) +} + // Linkify returns an ANSI escape sequence with an hyperlink, if the writer // supports colors. func Linkify(text, url string, w io.Writer) string { diff --git a/internal/display/apps.go b/internal/display/apps.go index 8d5098748..6a47bc149 100644 --- a/internal/display/apps.go +++ b/internal/display/apps.go @@ -15,6 +15,10 @@ const ( quickstartsRegularWeb = "https://auth0.com/docs/quickstart/webapp" quickstartsM2M = "https://auth0.com/docs/quickstart/backend" quickstartsGeneric = "https://auth0.com/docs/quickstarts" + friendlyM2M = "machine to machine" + friendlyNative = "native" + friendlySpa = "single page application" + friendlyReg = "regular web application" ) type applicationView struct { @@ -68,7 +72,7 @@ func (v *applicationView) AsTableRow() []string { if v.revealSecret { return []string{ v.Name, - v.Type, + applyColor(v.Type), ansi.Faint(v.ClientID), ansi.Italic(v.ClientSecret), strings.Join(v.Callbacks, ", "), @@ -76,7 +80,7 @@ func (v *applicationView) AsTableRow() []string { } return []string{ v.Name, - v.Type, + applyColor(v.Type), ansi.Faint(v.ClientID), strings.Join(v.Callbacks, ", "), } @@ -94,7 +98,7 @@ func (v *applicationView) KeyValues() [][]string { []string{"CLIENT ID", ansi.Faint(v.ClientID)}, []string{"NAME", v.Name}, []string{"DESCRIPTION", v.Description}, - []string{"TYPE", v.Type}, + []string{"TYPE", applyColor(v.Type)}, []string{"CLIENT SECRET", ansi.Italic(v.ClientSecret)}, []string{"CALLBACKS", callbacks}, []string{"ALLOWED LOGOUT URLS", allowedLogoutURLs}, @@ -109,7 +113,7 @@ func (v *applicationView) KeyValues() [][]string { []string{"CLIENT ID", ansi.Faint(v.ClientID)}, []string{"NAME", v.Name}, []string{"DESCRIPTION", v.Description}, - []string{"TYPE", v.Type}, + []string{"TYPE", applyColor(v.Type)}, []string{"CALLBACKS", callbacks}, []string{"ALLOWED LOGOUT URLS", allowedLogoutURLs}, []string{"ALLOWED ORIGINS", allowedOrigins}, @@ -145,14 +149,14 @@ func (v *applicationListView) AsTableRow() []string { return []string{ ansi.Faint(v.ClientID), v.Name, - v.Type, + applyColor(v.Type), ansi.Italic(v.ClientSecret), } } return []string{ ansi.Faint(v.ClientID), v.Name, - v.Type, + applyColor(v.Type), } } @@ -267,16 +271,16 @@ func appTypeFor(v *string) string { return "generic" case *v == "non_interactive": - return "machine to machine" + return friendlyM2M case *v == "native": - return "native" + return friendlyNative case *v == "spa": - return "single page application" + return friendlySpa case *v == "regular_web": - return "regular web application" + return friendlyReg default: return *v @@ -305,3 +309,18 @@ func interfaceSliceToString(s []interface{}) []string { } return res } + +func applyColor(a string) string { + switch { + case a == friendlyM2M: + return ansi.Green(a) + case a == friendlyNative: + return ansi.Cyan(a) + case a == friendlySpa: + return ansi.Blue(a) + case a == friendlyReg: + return ansi.Magenta(a) + default: + return a + } +}