From a1ff80111390e5c5654ab69061306106cd2de4ae Mon Sep 17 00:00:00 2001 From: Andy Herzog Date: Fri, 26 Mar 2021 14:38:18 -0600 Subject: [PATCH 1/2] feat: color code app types --- internal/ansi/ansi.go | 36 ++++++++++++++++++++++++++++++++++++ internal/display/apps.go | 31 +++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 6 deletions(-) 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..0663f76a1 100644 --- a/internal/display/apps.go +++ b/internal/display/apps.go @@ -68,7 +68,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 +76,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 +94,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 +109,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 +145,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), } } @@ -305,3 +305,22 @@ func interfaceSliceToString(s []interface{}) []string { } return res } + +func applyColor(a string) string { + switch { + case a == "machine to machine": + return ansi.Green(a) + + case a == "native": + return ansi.Cyan(a) + + case a == "single page application": + return ansi.Blue(a) + + case a == "regular web application": + return ansi.Magenta(a) + + default: + return a + } +} From b1f05d943fbf5b62e91268da5fb691cebf17a087 Mon Sep 17 00:00:00 2001 From: Andy Herzog Date: Fri, 26 Mar 2021 16:45:32 -0600 Subject: [PATCH 2/2] refactor: add consts --- internal/display/apps.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/display/apps.go b/internal/display/apps.go index 0663f76a1..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 { @@ -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 @@ -308,18 +312,14 @@ func interfaceSliceToString(s []interface{}) []string { func applyColor(a string) string { switch { - case a == "machine to machine": + case a == friendlyM2M: return ansi.Green(a) - - case a == "native": + case a == friendlyNative: return ansi.Cyan(a) - - case a == "single page application": + case a == friendlySpa: return ansi.Blue(a) - - case a == "regular web application": + case a == friendlyReg: return ansi.Magenta(a) - default: return a }