diff --git a/pkg/log/status.go b/pkg/log/status.go index 17f891884..f2135df1a 100644 --- a/pkg/log/status.go +++ b/pkg/log/status.go @@ -292,8 +292,7 @@ func Warning(a ...interface{}) { // ⚠ func Fwarning(out io.Writer, a ...interface{}) { if !IsJSON() { - yellow := color.New(color.FgYellow).SprintFunc() - fmt.Fprintf(out, "%s%s%s%s", prefixSpacing, yellow(getWarningString()), suffixSpacing, fmt.Sprintln(a...)) + Fwarningf(out, "%s", a...) } } @@ -301,10 +300,7 @@ func Fwarning(out io.Writer, a ...interface{}) { // // ⚠ func Warningf(format string, a ...interface{}) { - if !IsJSON() { - yellow := color.New(color.FgYellow).SprintFunc() - fmt.Fprintf(GetStderr(), " %s%s%s\n", yellow(getWarningString()), suffixSpacing, fmt.Sprintf(format, a...)) - } + Fwarningf(GetStderr(), format, a...) } // Fwarningf will output in an appropriate "warning" manner @@ -313,10 +309,28 @@ func Warningf(format string, a ...interface{}) { func Fwarningf(w io.Writer, format string, a ...interface{}) { if !IsJSON() { yellow := color.New(color.FgYellow).SprintFunc() - fmt.Fprintf(w, " %s%s%s\n", yellow(getWarningString()), suffixSpacing, fmt.Sprintf(format, a...)) + fullMessage := fmt.Sprintf("%s%s%s", getWarningString(), suffixSpacing, fmt.Sprintf(format, a...)) + fmt.Fprintln(w, yellow(wrapWarningMessage(fullMessage))) } } +func wrapWarningMessage(fullMessage string) string { + if fullMessage == "" || strings.TrimSpace(fullMessage) == "" { + return fullMessage + } + split := strings.Split(fullMessage, "\n") + max := 0 + for _, s := range split { + if len(s) > max { + max = len(s) + } + } + h := strings.Repeat("=", max) + return fmt.Sprintf(`%[1]s +%[2]s +%[1]s`, h, fullMessage, h) +} + // Fsuccess will output in an appropriate "progress" manner in out writer // // ✓ @@ -330,13 +344,9 @@ func Fsuccess(out io.Writer, a ...interface{}) { // DisplayExperimentalWarning displays the experimental mode warning message. func DisplayExperimentalWarning() { if !IsJSON() { - yellow := color.New(color.FgYellow).SprintFunc() - h := "============================================================================" - fmt.Fprintln(GetStdout(), yellow(fmt.Sprintf(`%[1]s -%s Experimental mode enabled. Use at your own risk. -More details on https://odo.dev/docs/user-guides/advanced/experimental-mode -%[1]s -`, h, getWarningString()))) + msg := `Experimental mode enabled. Use at your own risk. +More details on https://odo.dev/docs/user-guides/advanced/experimental-mode` + Fwarningf(GetStdout(), msg) } } diff --git a/pkg/log/status_test.go b/pkg/log/status_test.go new file mode 100644 index 000000000..2ee498ebf --- /dev/null +++ b/pkg/log/status_test.go @@ -0,0 +1,64 @@ +package log + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func Test_wrapWarningMessage(t *testing.T) { + type args struct { + fullMessage string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "empty message", + args: args{ + fullMessage: "", + }, + want: "", + }, + { + name: "single-line message", + args: args{ + fullMessage: "Lorem Ipsum Dolor Sit Amet", + }, + want: `========================== +Lorem Ipsum Dolor Sit Amet +==========================`, + }, + { + name: "multi-line message", + args: args{ + fullMessage: ` +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Aenean vel faucibus ex. +Nulla in magna sem. +Vivamus condimentum ultricies erat, in ullamcorper risus tempor nec. +Nam sed risus blandit, +`, + }, + want: `==================================================================== + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Aenean vel faucibus ex. +Nulla in magna sem. +Vivamus condimentum ultricies erat, in ullamcorper risus tempor nec. +Nam sed risus blandit, + +====================================================================`, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := wrapWarningMessage(tt.args.fullMessage) + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("wrapWarningMessage() mismatch (-want +got):\n%s", diff) + } + }) + } +} diff --git a/pkg/odo/genericclioptions/util.go b/pkg/odo/genericclioptions/util.go index a068c7077..3ea4b9cf2 100644 --- a/pkg/odo/genericclioptions/util.go +++ b/pkg/odo/genericclioptions/util.go @@ -2,10 +2,12 @@ package genericclioptions import ( "fmt" + + v1 "k8s.io/api/core/v1" + "github.com/redhat-developer/odo/pkg/kclient" "github.com/redhat-developer/odo/pkg/log" pkgUtil "github.com/redhat-developer/odo/pkg/util" - v1 "k8s.io/api/core/v1" dfutil "github.com/devfile/library/v2/pkg/util" ) @@ -47,7 +49,7 @@ func WarnIfDefaultNamespace(namespace string, kubeClient kclient.ClientInterface noun = "project" } fmt.Println() - log.Warningf("You are using \"default\" %[1]s, odo may not work as expected in the default %[1]s.", noun) - log.Warningf("You may set a new %[1]s by running `odo create %[1]s `, or set an existing one by running `odo set %[1]s `", noun) + log.Warningf(`You are using "default" %[1]s, odo may not work as expected in the default %[1]s. +You may set a new %[1]s by running `+"`odo create %[1]s `, or set an existing one by running `odo set %[1]s `", noun) } } diff --git a/tests/helper/helper_documentation.go b/tests/helper/helper_documentation.go index 14c623ca6..e8f5edbfb 100644 --- a/tests/helper/helper_documentation.go +++ b/tests/helper/helper_documentation.go @@ -67,6 +67,9 @@ func StripSpinner(docString string) (returnString string) { if strings.HasPrefix(line, "⚠") && !strings.Contains(line, "Pod is Pending") { continue } + if strings.HasPrefix(line, "===") { + continue + } // for some reason, splitting the docString by \n does not split the spinner frames, // so we perform a side operation to remove the extra spinner frames that are not present in the final output