diff --git a/cmd/zrok/status.go b/cmd/zrok/status.go index d9d2af99..4de14e54 100644 --- a/cmd/zrok/status.go +++ b/cmd/zrok/status.go @@ -50,7 +50,6 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) { _, _ = fmt.Fprintf(os.Stderr, "\n") if !env.IsEnabled() { - tui.Warning("Unable to load your local environment!\n") _, _ = fmt.Fprintf(os.Stderr, "To create a local environment use the %v command.\n", tui.Code.Render("zrok enable")) } else { _, _ = fmt.Fprintf(os.Stdout, tui.Code.Render("Environment")+":\n\n") diff --git a/environment/api.go b/environment/api.go index 6d2bae8c..1c100635 100644 --- a/environment/api.go +++ b/environment/api.go @@ -33,7 +33,11 @@ type Root interface { } func LoadRoot() (Root, error) { - return env_v0_3.Load() + if assert, err := env_v0_3.Assert(); assert && err == nil { + return env_v0_3.Load() + } else { + return nil, err + } } func ListRoots() ([]*env_core.Metadata, error) { diff --git a/environment/env_v0_3/root.go b/environment/env_v0_3/root.go index 68e1809b..f8034593 100644 --- a/environment/env_v0_3/root.go +++ b/environment/env_v0_3/root.go @@ -16,6 +16,21 @@ type Root struct { env *env_core.Environment } +func Assert() (bool, error) { + exists, err := rootExists() + if err != nil { + return true, err + } + if exists { + meta, err := loadMetadata() + if err != nil { + return true, err + } + return meta.V == V, nil + } + return false, nil +} + func Load() (*Root, error) { r := &Root{} exists, err := rootExists() @@ -62,7 +77,7 @@ func rootExists() (bool, error) { if err != nil { return false, err } - return true, err + return true, nil } func assertMetadata() error {