提交 c10878a8 编写于 作者: M Medya Gh

better error handling

上级 b332f04a
...@@ -53,16 +53,19 @@ var ProfileCmd = &cobra.Command{ ...@@ -53,16 +53,19 @@ var ProfileCmd = &cobra.Command{
exit.WithError("Setting profile failed", err) exit.WithError("Setting profile failed", err)
} }
cc, err := pkgConfig.Load() 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) { if err != nil && !os.IsNotExist(err) {
console.ErrLn("Error loading profile config: %v", err) console.ErrLn("Error loading profile config: %v", err)
} }
if cc.MachineConfig.KeepContext { if err == nil {
console.Success("Skipped switching kubectl context for %s , because --keep-context", profile) if cc.MachineConfig.KeepContext {
console.Success("To connect to this cluster, use: kubectl --context=%s", profile) console.Success("Skipped switching kubectl context for %s , because --keep-context", profile)
} else { console.Success("To connect to this cluster, use: kubectl --context=%s", profile)
err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile) } else {
if err != nil { err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile)
console.ErrLn("error while setting kubectl current context : %v", err) if err != nil {
console.ErrLn("Error while setting kubectl current context : %v", err)
}
} }
} }
console.Success("minikube profile was successfully set to %s", profile) console.Success("minikube profile was successfully set to %s", profile)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册