Skip to content

Commit

Permalink
Console output cleanup (#4825)
Browse files Browse the repository at this point in the history
* Console output cleanup

* comment fix

* Fixing out.Out stutter

* Fix invalid template

* Change profile_list.go to new console functions

* more merge stuff
  • Loading branch information
sharifelgamal authored Jul 20, 2019
1 parent 784717c commit 6552436
Show file tree
Hide file tree
Showing 53 changed files with 312 additions and 416 deletions.
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)

const longDescription = `
Expand Down Expand Up @@ -73,7 +73,7 @@ var completionCmd = &cobra.Command{
exit.UsageT("Usage: minikube completion SHELL")
}
if args[0] != "bash" && args[0] != "zsh" {
exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", console.Arg{"name": args[0]})
exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]})
} else if args[0] == "bash" {
err := GenerateBashCompletion(os.Stdout, cmd.Parent())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var addonsListCmd = &cobra.Command{
Long: "Lists all available minikube addons as well as their current statuses (enabled/disabled)",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
exit.Usage("usage: minikube addons list")
exit.UsageT("usage: minikube addons list")
}
err := addonList()
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"io/ioutil"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/service"
)

Expand All @@ -31,7 +31,7 @@ var addonsConfigureCmd = &cobra.Command{
Long: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
exit.Usage("usage: minikube addons configure ADDON_NAME")
exit.UsageT("usage: minikube addons configure ADDON_NAME")
}

addon := args[0]
Expand Down Expand Up @@ -77,7 +77,7 @@ var addonsConfigureCmd = &cobra.Command{
dat, err := ioutil.ReadFile(gcrPath)

if err != nil {
console.Failure("Error reading %s: %v", gcrPath, err)
out.FailureT("Error reading {{.path}}: {{.error}}", out.V{"path": gcrPath, "error": err})
} else {
gcrApplicationDefaultCredentials = string(dat)
}
Expand Down Expand Up @@ -109,7 +109,7 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
console.FailureT("ERROR creating `registry-creds-ecr` secret: {{.error}}", console.Arg{"error": err})
out.FailureT("ERROR creating `registry-creds-ecr` secret: {{.error}}", out.V{"error": err})
}

// Create GCR Secret
Expand All @@ -127,7 +127,7 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
console.FailureT("ERROR creating `registry-creds-gcr` secret: {{.error}}", console.Arg{"error": err})
out.FailureT("ERROR creating `registry-creds-gcr` secret: {{.error}}", out.V{"error": err})
}

// Create Docker Secret
Expand All @@ -146,14 +146,14 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
console.WarningT("ERROR creating `registry-creds-dpr` secret")
out.WarningT("ERROR creating `registry-creds-dpr` secret")
}
default:
console.FailureT("{{.name}} has no available configuration options", console.Arg{"name": addon})
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})
return
}

console.SuccessT("{{.name}} was successfully configured", console.Arg{"name": addon})
out.SuccessT("{{.name}} was successfully configured", out.V{"name": addon})
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package config

import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)

var addonsDisableCmd = &cobra.Command{
Expand All @@ -36,7 +36,7 @@ var addonsDisableCmd = &cobra.Command{
if err != nil {
exit.WithError("disable failed", err)
}
console.SuccessT(`"{{.minikube_addon}}" was successfully disabled`, console.Arg{"minikube_addon": addon})
out.SuccessT(`"{{.minikube_addon}}" was successfully disabled`, out.V{"minikube_addon": addon})
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package config

import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)

var addonsEnableCmd = &cobra.Command{
Expand All @@ -28,15 +28,15 @@ var addonsEnableCmd = &cobra.Command{
Long: "Enables the addon w/ADDON_NAME within minikube (example: minikube addons enable dashboard). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
exit.Usage("usage: minikube addons enable ADDON_NAME")
exit.UsageT("usage: minikube addons enable ADDON_NAME")
}

addon := args[0]
err := Set(addon, "true")
if err != nil {
exit.WithError("enable failed", err)
}
console.SuccessT("{{.addonName}} was successfully enabled", console.Arg{"addonName": addon})
out.SuccessT("{{.addonName}} was successfully enabled", out.V{"addonName": addon})
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/spf13/cobra"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/out"
)

var configGetCmd = &cobra.Command{
Expand All @@ -44,7 +44,7 @@ var configGetCmd = &cobra.Command{
return fmt.Errorf("no value for key '%s'", args[0])
}

console.OutLn(val)
out.Ln(val)
return nil
},
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/service"
)

Expand All @@ -47,7 +47,7 @@ var addonsOpenCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
t, err := template.New("addonsURL").Parse(addonsURLFormat)
if err != nil {
exit.UsageT("The value passed to --format is invalid: {{.error}}", console.Arg{"error": err})
exit.UsageT("The value passed to --format is invalid: {{.error}}", out.V{"error": err})
}
addonsURLTemplate = t
},
Expand All @@ -68,7 +68,7 @@ var addonsOpenCmd = &cobra.Command{
if !ok {
exit.WithCodeT(exit.Data, `addon '{{.name}}' is not a valid addon packaged with minikube.
To see the list of available addons run:
minikube addons list`, console.Arg{"name": addonName})
minikube addons list`, out.V{"name": addonName})
}
ok, err = addon.IsEnabled()
if err != nil {
Expand All @@ -77,24 +77,24 @@ minikube addons list`, console.Arg{"name": addonName})
if !ok {
exit.WithCodeT(exit.Unavailable, `addon '{{.name}}' is currently not enabled.
To enable this addon run:
minikube addons enable {{.name}}`, console.Arg{"name": addonName})
minikube addons enable {{.name}}`, out.V{"name": addonName})
}

namespace := "kube-system"
key := "kubernetes.io/minikube-addons-endpoint"

serviceList, err := service.GetServiceListByLabel(namespace, key, addonName)
if err != nil {
exit.WithCodeT(exit.Unavailable, "Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}", console.Arg{"namespace": namespace, "labelName": key, "addonName": addonName, "error": err})
exit.WithCodeT(exit.Unavailable, "Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}", out.V{"namespace": namespace, "labelName": key, "addonName": addonName, "error": err})
}
if len(serviceList.Items) == 0 {
exit.WithCodeT(exit.Config, `This addon does not have an endpoint defined for the 'addons open' command.
You can add one by annotating a service with the label {{.labelName}}:{{.addonName}}`, console.Arg{"labelName": key, "addonName": addonName})
You can add one by annotating a service with the label {{.labelName}}:{{.addonName}}`, out.V{"labelName": key, "addonName": addonName})
}
for i := range serviceList.Items {
svc := serviceList.Items[i].ObjectMeta.Name
if err := service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate, addonsURLMode, https, wait, interval); err != nil {
exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", console.Arg{"error": err})
exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", out.V{"error": err})
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
pkgutil "k8s.io/minikube/pkg/util"
)

Expand All @@ -36,7 +36,7 @@ var ProfileCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
profile := viper.GetString(pkgConfig.MachineProfile)
console.OutT(console.Empty, profile)
out.T(out.Empty, profile)
os.Exit(0)
}

Expand All @@ -55,19 +55,19 @@ var ProfileCmd = &cobra.Command{
cc, err := pkgConfig.Load()
// might err when loading older version of cfg file that doesn't have KeepContext field
if err != nil && !os.IsNotExist(err) {
console.ErrT(console.Sad, `Error loading profile config: {{.error}}`, console.Arg{"error": err})
out.ErrT(out.Sad, `Error loading profile config: {{.error}}`, out.V{"error": err})
}
if err == nil {
if cc.MachineConfig.KeepContext {
console.SuccessT("Skipped switching kubectl context for {{.profile_name}} , because --keep-context", console.Arg{"profile_name": profile})
console.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", console.Arg{"profile_name": profile})
out.SuccessT("Skipped switching kubectl context for {{.profile_name}} , because --keep-context", out.V{"profile_name": profile})
out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile})
} else {
err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile)
if err != nil {
console.ErrT(console.Sad, `Error while setting kubectl current context : {{.error}}`, console.Arg{"error": err})
out.ErrT(out.Sad, `Error while setting kubectl current context : {{.error}}`, out.V{"error": err})
}
}
}
console.SuccessT("minikube profile was successfully set to {{.profile_name}}", console.Arg{"profile_name": profile})
out.SuccessT("minikube profile was successfully set to {{.profile_name}}", out.V{"profile_name": profile})
},
}
12 changes: 6 additions & 6 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"strconv"

"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,18 +55,18 @@ var profileListCmd = &cobra.Command{
table.Render()

if invalidProfiles != nil {
console.OutT(console.WarningType, "Found {{.number}} invalid profile(s) ! ", console.Arg{"number": len(invalidProfiles)})
out.T(out.WarningType, "Found {{.number}} invalid profile(s) ! ", out.V{"number": len(invalidProfiles)})
for _, p := range invalidProfiles {
console.OutT(console.Empty, "\t "+p.Name)
out.T(out.Empty, "\t "+p.Name)
}
console.OutT(console.Tip, "You can delete them using the following command(s): ")
out.T(out.Tip, "You can delete them using the following command(s): ")
for _, p := range invalidProfiles {
console.Out(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name))
out.String(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name))
}

}
if err != nil {
exit.WithCode(exit.Config, fmt.Sprintf("error loading profiles: %v", err))
exit.WithCodeT(exit.Config, fmt.Sprintf("error loading profiles: %v", err))
}
},
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/minikube/cmd/config/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/golang/glog"
"golang.org/x/crypto/ssh/terminal"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/out"
)

// AskForYesNoConfirmation asks the user for confirmation. A user must type in "yes" or "no" and
Expand All @@ -36,7 +36,7 @@ func AskForYesNoConfirmation(s string, posResponses, negResponses []string) bool
reader := bufio.NewReader(os.Stdin)

for {
console.Out("%s [y/n]: ", s)
out.String("%s [y/n]: ", s)

response, err := reader.ReadString('\n')
if err != nil {
Expand All @@ -49,7 +49,7 @@ func AskForYesNoConfirmation(s string, posResponses, negResponses []string) bool
case containsString(negResponses, r):
return false
default:
console.Err("Please type yes or no:")
out.Err("Please type yes or no:")
}
}
}
Expand All @@ -63,7 +63,7 @@ func AskForStaticValue(s string) string {

// Can't have zero length
if len(response) == 0 {
console.Err("--Error, please enter a value:")
out.Err("--Error, please enter a value:")
continue
}
return response
Expand All @@ -78,7 +78,7 @@ func AskForStaticValueOptional(s string) string {
}

func getStaticValue(reader *bufio.Reader, s string) string {
console.Out("%s", s)
out.String("%s", s)

response, err := reader.ReadString('\n')
if err != nil {
Expand Down Expand Up @@ -110,7 +110,7 @@ func concealableAskForStaticValue(readWriter io.ReadWriter, promptString string,
}
response = strings.TrimSpace(response)
if len(response) == 0 {
console.Warning("Please enter a value:")
out.WarningT("Please enter a value:")
continue
}
return response, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var configSetCmd = &cobra.Command{
These values can be overwritten by flags or environment variables at runtime.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
exit.Usage("usage: minikube config set PROPERTY_NAME PROPERTY_VALUE")
exit.UsageT("usage: minikube config set PROPERTY_NAME PROPERTY_VALUE")
}
err := Set(args[0], args[1])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var configUnsetCmd = &cobra.Command{
Long: "unsets PROPERTY_NAME from the minikube config file. Can be overwritten by flags or environmental variables",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
exit.Usage("usage: minikube config unset PROPERTY_NAME")
exit.UsageT("usage: minikube config unset PROPERTY_NAME")
}
err := unset(args[0])
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/storageclass"
)

Expand Down Expand Up @@ -130,7 +130,7 @@ func EnableOrDisableAddon(name string, val string) error {

cfg, err := config.Load()
if err != nil && !os.IsNotExist(err) {
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", console.Arg{"error": err})
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err})
}

data := assets.GenerateTemplateData(cfg.KubernetesConfig)
Expand Down Expand Up @@ -158,7 +158,7 @@ func enableOrDisableAddonInternal(addon *assets.Addon, cmd command.Runner, data
var err error
// check addon status before enabling/disabling it
if err := isAddonAlreadySet(addon, enable); err != nil {
console.ErrT(console.Conflict, "{{.error}}", console.Arg{"error": err})
out.ErrT(out.Conflict, "{{.error}}", out.V{"error": err})
os.Exit(0)
}

Expand Down
Loading

0 comments on commit 6552436

Please sign in to comment.