From f5cbb354a901919aa485d75c1414d17e14c54e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olive=CC=81r=20Falvai?= Date: Fri, 11 Nov 2022 13:29:20 +0100 Subject: [PATCH] Colored error experiments --- log/colorstring/colorstring.go | 16 ++++----- log/colorstring/colorstring_test.go | 50 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/log/colorstring/colorstring.go b/log/colorstring/colorstring.go index 5401b91..ee336e4 100644 --- a/log/colorstring/colorstring.go +++ b/log/colorstring/colorstring.go @@ -23,7 +23,7 @@ const ( // ColorFunc ... type ColorFunc func(a ...interface{}) string -func addColor(color Color, msg string) string { +func AddColor(color Color, msg string) string { return string(color) + msg + string(resetColor) } @@ -34,37 +34,37 @@ func NoColor(a ...interface{}) string { // Black ... func Black(a ...interface{}) string { - return addColor(blackColor, fmt.Sprint(a...)) + return AddColor(blackColor, fmt.Sprint(a...)) } // Red ... func Red(a ...interface{}) string { - return addColor(redColor, fmt.Sprint(a...)) + return AddColor(redColor, fmt.Sprint(a...)) } // Green ... func Green(a ...interface{}) string { - return addColor(greenColor, fmt.Sprint(a...)) + return AddColor(greenColor, fmt.Sprint(a...)) } // Yellow ... func Yellow(a ...interface{}) string { - return addColor(yellowColor, fmt.Sprint(a...)) + return AddColor(yellowColor, fmt.Sprint(a...)) } // Blue ... func Blue(a ...interface{}) string { - return addColor(blueColor, fmt.Sprint(a...)) + return AddColor(blueColor, fmt.Sprint(a...)) } // Magenta ... func Magenta(a ...interface{}) string { - return addColor(magentaColor, fmt.Sprint(a...)) + return AddColor(magentaColor, fmt.Sprint(a...)) } // Cyan ... func Cyan(a ...interface{}) string { - return addColor(cyanColor, fmt.Sprint(a...)) + return AddColor(cyanColor, fmt.Sprint(a...)) } // ColorfFunc ... diff --git a/log/colorstring/colorstring_test.go b/log/colorstring/colorstring_test.go index 0597423..9df2e74 100644 --- a/log/colorstring/colorstring_test.go +++ b/log/colorstring/colorstring_test.go @@ -2,6 +2,7 @@ package colorstring import ( "fmt" + "strings" "testing" "github.com/stretchr/testify/require" @@ -16,7 +17,7 @@ func TestAddColor(t *testing.T) { t.Log("colored_string = color + string + reset_color") { desiredColored := "\x1b[30;1m" + "test" + "\x1b[0m" - colored := addColor(blackColor, "test") + colored := AddColor(blackColor, "test") require.Equal(t, desiredColored, colored) } } @@ -52,3 +53,50 @@ func TestBlackf(t *testing.T) { require.Equal(t, desiredColored, colored) } } + +func TestGitError(t *testing.T) { + fmt.Printf(` +Error: + fetch failed: + remote: Support for password authentication was removed on August 13, 2021. + remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. + fatal: Authentication failed for 'https://github.com/Intan90002/empty.git/' +`) + + fmt.Println(strings.Repeat("-", 80)) + fmt.Printf(` +%s: + fetch failed: + remote: Support for password authentication was removed on August 13, 2021. + remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. + fatal: %s +`, + Red("Error"), + Redf("Authentication failed for '%s'", Cyan("https://github.com/Intan90002/empty.git/")), + ) +} + +func TestXcodeError(t *testing.T) { + fmt.Printf(` +Command failed with exit status 70 (xcodebuild "-exportArchive" "-archivePath" "./code-sign-test.xcarchive" "-exportPath" "./exported" "-exportOptionsPlist" "./export_options.plist"): + error: exportArchive: "share-extension.appex" requires a provisioning profile. + error: exportArchive: "code-sign-test.app" requires a provisioning profile. + error: exportArchive: "watchkit-app.app" requires a provisioning profile. + error: exportArchive: "watchkit-app Extension.appex" requires a provisioning profile. +`) + + fmt.Println(strings.Repeat("-", 80)) + fmt.Printf(` +Command failed with exit status 70 (%s): + error: exportArchive: %s + error: exportArchive: %s + error: exportArchive: %s + error: exportArchive: %s +`, + Cyan(`xcodebuild "-exportArchive" "-archivePath" "./code-sign-test.xcarchive" "-exportPath" "./exported" "-exportOptionsPlist" "./export_options.plist"`), + Red(`"share-extension.appex" requires a provisioning profile.`), + Red(`"code-sign-test.app" requires a provisioning profile.`), + Red(`"watchkit-app.app" requires a provisioning profile.`), + Red(`"watchkit-app Extension.appex" requires a provisioning profile.`), + ) +}