diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index d8250bb66c2d..028b29df82a4 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -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) } diff --git a/go.mod b/go.mod index 602798f547c2..b625e4ad14b6 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index c7af4fd31626..ce0d8f4ecaca 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/minikube/console/console.go b/pkg/minikube/console/console.go index 0e2389025f4a..f753afbdff0e 100644 --- a/pkg/minikube/console/console.go +++ b/pkg/minikube/console/console.go @@ -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) } @@ -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) } @@ -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()) diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index c86c4fe0555a..1a16dc99461d 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -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 @@ -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 diff --git a/pkg/minikube/exit/exit.go b/pkg/minikube/exit/exit.go index a814aad54719..6096d5c91ffe 100644 --- a/pkg/minikube/exit/exit.go +++ b/pkg/minikube/exit/exit.go @@ -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) @@ -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 @@ -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) @@ -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) } @@ -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) @@ -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") } diff --git a/translations/fr-FR.json b/translations/fr-FR.json index 76d792589fd6..2ef265dc931f 100644 --- a/translations/fr-FR.json +++ b/translations/fr-FR.json @@ -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": "", @@ -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 ...": "", @@ -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}}": "" } \ No newline at end of file diff --git a/translations/zh-CN.json b/translations/zh-CN.json index b3dd4ce6721f..37282085d46e 100644 --- a/translations/zh-CN.json +++ b/translations/zh-CN.json @@ -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": "", @@ -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 ...": "", @@ -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}}": "" } \ No newline at end of file