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

Add T versions of the console convenience functions #4796

Merged
merged 6 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if err = cluster.DeleteHost(api); err != nil {
switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
console.OutStyle(console.Meh, "%q cluster does not exist", profile)
console.OutT(console.Meh, `"{{.name}}" cluster does not exist`, console.Arg{"name": profile})
default:
exit.WithError("Failed to delete cluster", err)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Parallels/docker-machine-parallels v1.3.0
github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/blang/semver v3.5.0+incompatible
github.com/c4milo/gotoolkit v0.0.0-20170318115440-bcc06269efa9 // indirect
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
Expand All @@ -18,6 +19,7 @@ require (
github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/glog v0.0.0-20141105023935-44145f04b68c
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/Parallels/docker-machine-parallels v1.3.0 h1:RG1fyf3v1GwXMCeHRiZkB4tL
github.com/Parallels/docker-machine-parallels v1.3.0/go.mod h1:HCOMm3Hulq/xuEVQMyZOuQlA+dSZpFY5kdCTZWjMVis=
github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2 h1:k1A7eIeUk6rnX2yuagwljW/pDezkK8oSpvPumT9zdZY=
github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/blang/semver v3.5.0+incompatible h1:CGxCgetQ64DKk7rdZ++Vfnb1+ogGNnB17OJKJXD2Cfs=
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/c4milo/gotoolkit v0.0.0-20170318115440-bcc06269efa9 h1:+ziP/wVJWuAORkjv7386TRidVKY57X0bXBZFMeFlW+U=
Expand Down Expand Up @@ -36,6 +38,8 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e h1:ago6fNuQ6IhszPsXkeU7qRCyfsIX7L67WDybsAPkLl8=
github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
Expand Down
28 changes: 24 additions & 4 deletions pkg/minikube/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func OutStyle(style StyleEnum, format string, a ...interface{}) {
}

// OutT writes a stylized and templated message to stdout
func OutT(style StyleEnum, format string, a map[string]interface{}) {
outStyled := applyTemplateFormatting(style, useColor, format, a)
func OutT(style StyleEnum, format string, a ...Arg) {
outStyled := applyTemplateFormatting(style, useColor, format, a...)
Out(outStyled)
}

Expand Down Expand Up @@ -96,8 +96,8 @@ func ErrStyle(style StyleEnum, format string, a ...interface{}) {
}

// ErrT writes a stylized and templated error message to stderr
func ErrT(style StyleEnum, format string, a map[string]interface{}) {
errStyled := applyTemplateFormatting(style, useColor, format, a)
func ErrT(style StyleEnum, format string, a ...Arg) {
errStyled := applyTemplateFormatting(style, useColor, format, a...)
Err(errStyled)
}

Expand Down Expand Up @@ -138,6 +138,26 @@ func Failure(format string, a ...interface{}) {
ErrStyle(FailureType, format, a...)
}

// SuccessT is a shortcut for writing a templated success message to stdout
func SuccessT(format string, a ...Arg) {
OutT(SuccessType, format, a...)
}

// FatalT is a shortcut for writing a templated fatal message to stderr
func FatalT(format string, a ...Arg) {
ErrT(FatalType, format, a...)
}

// WarningT is a shortcut for writing a templated warning message to stderr
func WarningT(format string, a ...Arg) {
ErrT(WarningType, format, a...)
}

// FailureT is a shortcut for writing a templated failure message to stderr
func FailureT(format string, a ...Arg) {
ErrT(FailureType, format, a...)
}

// SetOutFile configures which writer standard output goes to.
func SetOutFile(w fdWriter) {
glog.Infof("Setting OutFile to fd %d ...", w.Fd())
Expand Down
8 changes: 5 additions & 3 deletions pkg/minikube/console/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func applyStyle(style StyleEnum, useColor bool, format string) string {
return applyPrefix(s.Prefix, format)
}

func applyTemplateFormatting(style StyleEnum, useColor bool, format string, a map[string]interface{}) string {
func applyTemplateFormatting(style StyleEnum, useColor bool, format string, a ...Arg) string {
format = applyStyle(style, useColor, format)

var buf bytes.Buffer
Expand All @@ -160,8 +160,10 @@ func applyTemplateFormatting(style StyleEnum, useColor bool, format string, a ma
glog.Infof("Initializing template failed. Returning raw string.")
return format
}

err = t.Execute(&buf, a)
if len(a) == 0 {
a[0] = Arg{}
}
err = t.Execute(&buf, a[0])
if err != nil {
glog.Infof("Executing template failed. Returning raw string.")
return format
Expand Down
29 changes: 21 additions & 8 deletions pkg/minikube/exit/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/golang/glog"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/problem"
"k8s.io/minikube/pkg/minikube/translate"
)

// Exit codes based on sysexits(3)
Expand All @@ -50,6 +51,12 @@ func Usage(format string, a ...interface{}) {
os.Exit(BadUsage)
}

// UsageT outputs a templated usage error and exits with error code 64
func UsageT(format string, a ...console.Arg) {
console.ErrT(console.Usage, format, a...)
os.Exit(BadUsage)
}

// WithCode outputs a fatal error message and exits with a supplied error code.
func WithCode(code int, format string, a ...interface{}) {
// use Warning because Error will display a duplicate message to stderr
Expand All @@ -58,6 +65,12 @@ func WithCode(code int, format string, a ...interface{}) {
os.Exit(code)
}

// WithCodeT outputs a templated fatal error message and exits with the supplied error code.
func WithCodeT(code int, format string, a ...console.Arg) {
console.FatalT(format, a...)
os.Exit(code)
}

// WithError outputs an error and exits.
func WithError(msg string, err error) {
p := problem.FromError(err, runtime.GOOS)
Expand All @@ -71,11 +84,11 @@ func WithError(msg string, err error) {
// WithProblem outputs info related to a known problem and exits.
func WithProblem(msg string, p *problem.Problem) {
console.Err("\n")
console.Fatal(msg)
console.FatalT(msg)
p.Display()
console.Err("\n")
console.ErrStyle(console.Sad, "If the above advice does not help, please let us know: ")
console.ErrStyle(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose")
console.ErrT(console.Sad, "If the above advice does not help, please let us know: ")
console.ErrT(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose")
os.Exit(Config)
}

Expand All @@ -84,12 +97,12 @@ func WithLogEntries(msg string, err error, entries map[string][]string) {
displayError(msg, err)

for name, lines := range entries {
console.OutStyle(console.FailureType, "Problems detected in %q:", name)
console.OutT(console.FailureType, "Problems detected in {{.entry}}:", console.Arg{"entry": name})
if len(lines) > MaxLogEntries {
lines = lines[:MaxLogEntries]
}
for _, l := range lines {
console.OutStyle(console.LogEntry, l)
console.OutT(console.LogEntry, l)
}
}
os.Exit(Software)
Expand All @@ -99,8 +112,8 @@ func displayError(msg string, err error) {
// use Warning because Error will display a duplicate message to stderr
glog.Warningf(fmt.Sprintf("%s: %v", msg, err))
console.Err("\n")
console.Fatal("%s: %v", msg, err)
console.FatalT("{{.msg}}: {{.err}}", console.Arg{"msg": translate.T(msg), "err": err})
console.Err("\n")
console.ErrStyle(console.Sad, "Sorry that minikube crashed. If this was unexpected, we would love to hear from you:")
console.ErrStyle(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose")
console.ErrT(console.Sad, "Sorry that minikube crashed. If this was unexpected, we would love to hear from you:")
console.ErrT(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose")
}
5 changes: 4 additions & 1 deletion translations/fr-FR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"\"{{.name}}\" cluster does not exist": "",
"%q VM does not exist, nothing to stop": "",
"%q cluster does not exist": "",
"%q host does not exist, unable to show an IP": "",
Expand Down Expand Up @@ -148,6 +149,7 @@
"Please upgrade the 'docker-machine-driver-kvm2'. %s": "",
"Powering off %q via SSH ...": "",
"Problems detected in %q:": "",
"Problems detected in {{.entry}}:": "",
"Pulling images ...": "Extrayant les images ... ",
"Re-run 'minikube start' with --alsologtostderr -v=8 to see the VM driver error message": "",
"Re-using the currently running %s VM for %q ...": "",
Expand Down Expand Up @@ -274,5 +276,6 @@
"usage: minikube config unset PROPERTY_NAME": "",
"usage: minikube delete": "",
"usage: minikube profile [MINIKUBE_PROFILE_NAME]": "",
"zsh completion failed": ""
"zsh completion failed": "",
"{{.msg}}: {{.err}}": ""
}
5 changes: 4 additions & 1 deletion translations/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"\"{{.name}}\" cluster does not exist": "",
"%q VM does not exist, nothing to stop": "",
"%q cluster does not exist": "",
"%q host does not exist, unable to show an IP": "",
Expand Down Expand Up @@ -148,6 +149,7 @@
"Please upgrade the 'docker-machine-driver-kvm2'. %s": "",
"Powering off %q via SSH ...": "",
"Problems detected in %q:": "",
"Problems detected in {{.entry}}:": "",
"Pulling images ...": "拉取镜像 ...",
"Re-run 'minikube start' with --alsologtostderr -v=8 to see the VM driver error message": "",
"Re-using the currently running %s VM for %q ...": "",
Expand Down Expand Up @@ -274,5 +276,6 @@
"usage: minikube config unset PROPERTY_NAME": "",
"usage: minikube delete": "",
"usage: minikube profile [MINIKUBE_PROFILE_NAME]": "",
"zsh completion failed": ""
"zsh completion failed": "",
"{{.msg}}: {{.err}}": ""
}