environment load assert chain (#369); get rid of warnings in zrok status

This commit is contained in:
Michael Quigley 2023-07-14 10:51:35 -04:00
parent 4713243e2c
commit af77de015a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 21 additions and 3 deletions

View File

@ -50,7 +50,6 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
_, _ = fmt.Fprintf(os.Stderr, "\n") _, _ = fmt.Fprintf(os.Stderr, "\n")
if !env.IsEnabled() { 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")) _, _ = fmt.Fprintf(os.Stderr, "To create a local environment use the %v command.\n", tui.Code.Render("zrok enable"))
} else { } else {
_, _ = fmt.Fprintf(os.Stdout, tui.Code.Render("Environment")+":\n\n") _, _ = fmt.Fprintf(os.Stdout, tui.Code.Render("Environment")+":\n\n")

View File

@ -33,7 +33,11 @@ type Root interface {
} }
func LoadRoot() (Root, error) { func LoadRoot() (Root, error) {
if assert, err := env_v0_3.Assert(); assert && err == nil {
return env_v0_3.Load() return env_v0_3.Load()
} else {
return nil, err
}
} }
func ListRoots() ([]*env_core.Metadata, error) { func ListRoots() ([]*env_core.Metadata, error) {

View File

@ -16,6 +16,21 @@ type Root struct {
env *env_core.Environment 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) { func Load() (*Root, error) {
r := &Root{} r := &Root{}
exists, err := rootExists() exists, err := rootExists()
@ -62,7 +77,7 @@ func rootExists() (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
return true, err return true, nil
} }
func assertMetadata() error { func assertMetadata() error {