Skip to content

Commit

Permalink
Merge pull request #4162 from tstromberg/shorter-prefixes
Browse files Browse the repository at this point in the history
Standardize ASCII prefix for info, warning, and error messages
  • Loading branch information
k8s-ci-robot authored May 7, 2019
2 parents b936caf + 283d54c commit 2cd5336
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 79 deletions.
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

0 comments on commit 2cd5336

Please sign in to comment.