From 984f563e21dd59557f9f4b0b0425a2db6fdf3e63 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 30 May 2019 10:18:40 -0700 Subject: [PATCH] remove unnecessary String() implementation --- pkg/minikube/console/console.go | 11 +---- pkg/minikube/console/console_test.go | 2 +- pkg/minikube/console/style.go | 9 ++-- pkg/minikube/console/style_enum.go | 67 ---------------------------- 4 files changed, 7 insertions(+), 82 deletions(-) diff --git a/pkg/minikube/console/console.go b/pkg/minikube/console/console.go index 318b1cbd46..1013228947 100644 --- a/pkg/minikube/console/console.go +++ b/pkg/minikube/console/console.go @@ -71,10 +71,7 @@ func HasStyle(style StyleEnum) bool { // OutStyle writes a stylized and formatted message to stdout func OutStyle(style StyleEnum, format string, a ...interface{}) { - outStyled, err := applyStyle(style, useColor, format, a...) - if err != nil { - glog.Errorf("applyStyle(%s): %v", style, err) - } + outStyled := applyStyle(style, useColor, format, a...) // escape any outstanding '%' signs so that they don't get interpreted // as a formatting directive down the line @@ -102,11 +99,7 @@ func OutLn(format string, a ...interface{}) { // ErrStyle writes a stylized and formatted error message to stderr func ErrStyle(style StyleEnum, format string, a ...interface{}) { - format, err := applyStyle(style, useColor, format, a...) - if err != nil { - glog.Errorf("applyStyle(%s): %v", style, err) - ErrLn(format, a...) - } + format = applyStyle(style, useColor, format, a...) // escape any outstanding '%' signs so that they don't get interpreted // as a formatting directive down the line diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/console/console_test.go index f8170cb542..488e12e3e7 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/console/console_test.go @@ -66,7 +66,7 @@ func TestOutStyle(t *testing.T) { } for _, tc := range tests { for _, override := range []bool{true, false} { - t.Run(fmt.Sprintf("%s-override-%v", tc.style, override), func(t *testing.T) { + t.Run(fmt.Sprintf("%s-override-%v", tc.message, override), func(t *testing.T) { // Set MINIKUBE_IN_STYLE= os.Setenv(OverrideEnv, strconv.FormatBool(override)) f := newFakeFile() diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index 184d608266..e08286c385 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -17,7 +17,6 @@ limitations under the License. package console import ( - "fmt" "strings" "golang.org/x/text/message" @@ -136,7 +135,7 @@ func lowPrefix(s style) string { } // Apply styling to a format string -func applyStyle(style StyleEnum, useColor bool, format string, a ...interface{}) (string, error) { +func applyStyle(style StyleEnum, useColor bool, format string, a ...interface{}) string { p := message.NewPrinter(preferredLanguage) for i, x := range a { if _, ok := x.(int); ok { @@ -152,11 +151,11 @@ func applyStyle(style StyleEnum, useColor bool, format string, a ...interface{}) // Similar to CSS styles, if no style matches, output an unformatted string. if !ok { - return p.Sprintf(format, a...), fmt.Errorf("unknown style: %q", style) + return p.Sprintf(format, a...) } if !useColor { - return applyPrefix(lowPrefix(s), out), nil + return applyPrefix(lowPrefix(s), out) } - return applyPrefix(s.Prefix, out), nil + return applyPrefix(s.Prefix, out) } diff --git a/pkg/minikube/console/style_enum.go b/pkg/minikube/console/style_enum.go index 1fbf691790..6bd12e2a17 100644 --- a/pkg/minikube/console/style_enum.go +++ b/pkg/minikube/console/style_enum.go @@ -78,70 +78,3 @@ const ( MountOptions Fileserver ) - -func (style StyleEnum) String() string { - var s = []string{"Happy", - "SuccessType", - "FailureType", - "Conflict", - "FatalType", - "Notice", - "Ready", - "Running", - "Provisioning", - "Restarting", - "Reconfiguring", - "Stopping", - "Stopped", - "WarningType", - "Waiting", - "WaitingPods", - "Usage", - "Launch", - "Sad", - "ThumbsUp", - "Option", - "Command", - "LogEntry", - "Crushed", - "URL", - "Documentation", - "Issues", - "Issue", - "Check", - "IsoDownload", - "FileDownload", - "Caching", - "StartingVM", - "StartingNone", - "Resetting", - "DeletingHost", - "Copying", - "Connectivity", - "Internet", - "Mounting", - "Celebrate", - "ContainerRuntime", - "Docker", - "Crio", - "Containerd", - "Permissions", - "Enabling", - "Shutdown", - "Pulling", - "Verifying", - "VerifyingNoLine", - "Kubectl", - "Meh", - "Embarrassed", - "Tip", - "Unmount", - "MountOptions", - "Fileserver"} - - if style > Fileserver { - return "Unknown" - } - - return s[style] -}