Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize ASCII prefix for info, warning, and error messages #4162

Merged
merged 6 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 33 additions & 40 deletions pkg/minikube/console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package console

import (
"bytes"
"fmt"
"os"
"strconv"
"testing"

"golang.org/x/text/language"
Expand Down Expand Up @@ -48,49 +50,40 @@ func (f *fakeFile) String() string {
func TestOutStyle(t *testing.T) {

var tests = []struct {
style string
envValue string
message string
params []interface{}
want string
style string
message string
params []interface{}
want string
wantASCII string
}{
{"happy", "true", "This is happy.", nil, "😄 This is happy.\n"},
{"Docker", "true", "This is Docker.", nil, "🐳 This is Docker.\n"},
{"option", "true", "This is option.", nil, " ▪ This is option.\n"},
{
"option",
"true",
"Message with params: %s %s",
[]interface{}{"encode '%' signs", "%s%%%d"},
" ▪ Message with params: encode '%' signs %s%%%d\n",
},

{"happy", "false", "This is happy.", nil, "o This is happy.\n"},
{"Docker", "false", "This is Docker.", nil, "- This is Docker.\n"},
{"option", "false", "This is option.", nil, " - This is option.\n"},
{
"option",
"false",
"Message with params: %s %s",
[]interface{}{"encode '%' signs", "%s%%%d"},
" - Message with params: encode '%' signs %s%%%d\n",
},
{"issue", "true", "No separators for long ints: %d", []interface{}{10000}, " ▪ No separators for long ints: 10000\n"},
{"issue", "false", "No separators for long ints: %d", []interface{}{5000}, " - No separators for long ints: 5000\n"},
{"happy", "Happy", nil, "😄 Happy\n", "* Happy\n"},
{"option", "Option", nil, " ▪ Option\n", " - Option\n"},
{"warning", "Warning", nil, "⚠️ Warning\n", "! Warning\n"},
{"fatal", "Fatal: %v", []interface{}{"ugh"}, "💣 Fatal: ugh\n", "X Fatal: ugh\n"},
{"waiting-pods", "wait", nil, "⌛ wait", "* wait"},
{"issue", "http://i/%d", []interface{}{10000}, " ▪ http://i/10000\n", " - http://i/10000\n"},
{"usage", "raw: %s %s", []interface{}{"'%'", "%d"}, "💡 raw: '%' %d\n", "* raw: '%' %d\n"},
}
for _, tc := range tests {
t.Run(tc.style+"-"+tc.envValue, func(t *testing.T) {
os.Setenv(OverrideEnv, tc.envValue)
f := newFakeFile()
SetOutFile(f)
if err := OutStyle(tc.style, tc.message, tc.params...); err != nil {
t.Errorf("unexpected error: %q", err)
}
got := f.String()
if got != tc.want {
t.Errorf("OutStyle() = %q, want %q", got, tc.want)
}
})
for _, override := range []bool{true, false} {
t.Run(fmt.Sprintf("%s-override-%v", tc.style, override), func(t *testing.T) {
// Set MINIKUBE_IN_STYLE=<override>
os.Setenv(OverrideEnv, strconv.FormatBool(override))
f := newFakeFile()
SetOutFile(f)
if err := OutStyle(tc.style, tc.message, tc.params...); err != nil {
t.Errorf("unexpected error: %q", err)
}
got := f.String()
want := tc.wantASCII
if override {
want = tc.want
}
if got != want {
t.Errorf("OutStyle() = %q (%d runes), want %q (%d runes)", got, len(got), want, len(want))
}
})
}
}
}

Expand Down
84 changes: 45 additions & 39 deletions pkg/minikube/console/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ import (
)

var (
defaultLowPrefix = "- "
defautlLowIndentPrefix = " - "
// lowBullet is a bullet-point prefix for low-fi mode
lowBullet = "* "
// lowBullet is an indented bullet-point prefix for low-fi mode
lowIndent = " - "
// lowBullet is a warning prefix for low-fi mode
lowWarning = "! "
// lowBullet is an error prefix for low-fi mode
lowError = "X "
)

// style describes how to stylize a message.
Expand All @@ -42,47 +48,47 @@ type style struct {
// styles is a map of style name to style struct
// For consistency, ensure that emojis added render with the same width across platforms.
var styles = map[string]style{
"happy": {Prefix: "😄 ", LowPrefix: "o "},
"happy": {Prefix: "😄 "},
"success": {Prefix: "✅ "},
"failure": {Prefix: "❌ ", LowPrefix: "X "},
"conflict": {Prefix: "💥 ", LowPrefix: "x "},
"fatal": {Prefix: "💣 ", LowPrefix: "! "},
"notice": {Prefix: "📌 ", LowPrefix: "* "},
"ready": {Prefix: "🏄 ", LowPrefix: "= "},
"running": {Prefix: "🏃 ", LowPrefix: ": "},
"provisioning": {Prefix: "🌱 ", LowPrefix: "> "},
"restarting": {Prefix: "🔄 ", LowPrefix: ": "},
"reconfiguring": {Prefix: "📯 ", LowPrefix: ": "},
"stopping": {Prefix: "✋ ", LowPrefix: ": "},
"failure": {Prefix: "❌ "},
"conflict": {Prefix: "💥 ", LowPrefix: lowWarning},
"fatal": {Prefix: "💣 ", LowPrefix: lowError},
"notice": {Prefix: "📌 "},
"ready": {Prefix: "🏄 "},
"running": {Prefix: "🏃 "},
"provisioning": {Prefix: "🌱 "},
"restarting": {Prefix: "🔄 "},
"reconfiguring": {Prefix: "📯 "},
"stopping": {Prefix: "✋ "},
"stopped": {Prefix: "🛑 "},
"warning": {Prefix: "⚠️ ", LowPrefix: "! "},
"waiting": {Prefix: "⌛ ", LowPrefix: ": "},
"waiting-pods": {Prefix: "⌛ ", LowPrefix: ": ", OmitNewline: true},
"warning": {Prefix: "⚠️ ", LowPrefix: lowWarning},
"waiting": {Prefix: "⌛ "},
"waiting-pods": {Prefix: "⌛ ", OmitNewline: true},
"usage": {Prefix: "💡 "},
"launch": {Prefix: "🚀 "},
"sad": {Prefix: "😿 ", LowPrefix: "* "},
"sad": {Prefix: "😿 "},
"thumbs-up": {Prefix: "👍 "},
"option": {Prefix: " ▪ "}, // Indented bullet
"command": {Prefix: " ▪ "}, // Indented bullet
"log-entry": {Prefix: " "}, // Indent
"option": {Prefix: " ▪ ", LowPrefix: lowIndent}, // Indented bullet
"command": {Prefix: " ▪ ", LowPrefix: lowIndent}, // Indented bullet
"log-entry": {Prefix: " "}, // Indent
"crushed": {Prefix: "💔 "},
"url": {Prefix: "👉 "},
"url": {Prefix: "👉 ", LowPrefix: lowIndent},
"documentation": {Prefix: "📘 "},
"issues": {Prefix: "⁉️ "},
"issue": {Prefix: " ▪ "}, // Indented bullet
"issue": {Prefix: " ▪ ", LowPrefix: lowIndent}, // Indented bullet
"check": {Prefix: "✔️ "},

// Specialized purpose styles
"iso-download": {Prefix: "💿 ", LowPrefix: "@ "},
"file-download": {Prefix: "💾 ", LowPrefix: "@ "},
"caching": {Prefix: "🤹 ", LowPrefix: "$ "},
"starting-vm": {Prefix: "🔥 ", LowPrefix: "> "},
"starting-none": {Prefix: "🤹 ", LowPrefix: "> "},
"resetting": {Prefix: "🔄 ", LowPrefix: "# "},
"deleting-host": {Prefix: "🔥 ", LowPrefix: "x "},
"iso-download": {Prefix: "💿 "},
"file-download": {Prefix: "💾 "},
"caching": {Prefix: "🤹 "},
"starting-vm": {Prefix: "🔥 "},
"starting-none": {Prefix: "🤹 "},
"resetting": {Prefix: "🔄 "},
"deleting-host": {Prefix: "🔥 "},
"copying": {Prefix: "✨ "},
"connectivity": {Prefix: "📶 "},
"internet": {Prefix: "🌐 ", LowPrefix: "o "},
"internet": {Prefix: "🌐 "},
"mounting": {Prefix: "📁 "},
"celebrate": {Prefix: "🎉 "},
"container-runtime": {Prefix: "🎁 "},
Expand All @@ -95,13 +101,13 @@ var styles = map[string]style{
"pulling": {Prefix: "🚜 "},
"verifying": {Prefix: "🤔 "},
"verifying-noline": {Prefix: "🤔 ", OmitNewline: true},
"kubectl": {Prefix: "💗 ", LowPrefix: "+ "},
"meh": {Prefix: "🙄 ", LowPrefix: "? "},
"embarrassed": {Prefix: "🤦 ", LowPrefix: "* "},
"tip": {Prefix: "💡 ", LowPrefix: "i "},
"unmount": {Prefix: "🔥 ", LowPrefix: "x "},
"mount-options": {Prefix: "💾 ", LowPrefix: "o "},
"fileserver": {Prefix: "🚀 ", LowPrefix: "@ ", OmitNewline: true},
"kubectl": {Prefix: "💗 "},
"meh": {Prefix: "🙄 ", LowPrefix: lowWarning},
"embarrassed": {Prefix: "🤦 ", LowPrefix: lowWarning},
"tip": {Prefix: "💡 "},
"unmount": {Prefix: "🔥 "},
"mount-options": {Prefix: "💾 "},
"fileserver": {Prefix: "🚀 ", OmitNewline: true},
}

// Add a prefix to a string
Expand All @@ -124,9 +130,9 @@ func lowPrefix(s style) string {
return s.LowPrefix
}
if strings.HasPrefix(s.Prefix, " ") {
return defautlLowIndentPrefix
return lowIndent
}
return defaultLowPrefix
return lowBullet
}

// Apply styling to a format string
Expand Down