From c657f5778d8b4d11ec1393e033aa2fe4b4bde7fd Mon Sep 17 00:00:00 2001 From: Tristan Isham Date: Wed, 27 Mar 2024 23:56:00 -0400 Subject: [PATCH] trying to add mach aliases --- cli/config.go | 4 ++++ cli/use.go | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cli/config.go b/cli/config.go index ff0d1ca..dc6a16c 100644 --- a/cli/config.go +++ b/cli/config.go @@ -92,6 +92,10 @@ type ZigOnlVersion = map[string][]map[string]string // } // return nil // } +// TODO switch to error so we can handle common typos. Make it return an (error, bool) +func validVmuAlis(version string) bool { + return version == "default" || version == "mach" +} func (z ZVM) getVersion(version string) error { if _, err := os.Stat(filepath.Join(z.baseDir, version)); err != nil { diff --git a/cli/use.go b/cli/use.go index 30dcca0..7d2c8b5 100644 --- a/cli/use.go +++ b/cli/use.go @@ -19,12 +19,30 @@ import ( func (z *ZVM) Use(ver string) error { err := z.getVersion(ver) if errors.Is(err, os.ErrNotExist) { - fmt.Printf("It looks like %s isn't installed. Would you like to install it? [y/n]\n", ver) - if getConfirmation() { - err = z.Install(ver) - } else { - return fmt.Errorf("version %s is not installed", ver) + + // We might want to add an option in settings to toggle these in case some + // version map uses "default" as a version name. + switch ver { + case "default": + if err = z.Settings.ResetVersionMap(); err != nil { + return err + } + case "mach": + if err := z.Settings.SetVersionMapUrl("https://machengine.org/zig/index.json"); err != nil { + log.Info("Run `-vmu default` to reset your version map.") + } + default: + fmt.Printf("It looks like %s isn't installed. Would you like to install it? [y/n]\n", ver) + if getConfirmation() { + err = z.Install(ver) + } else { + return fmt.Errorf("version %s is not installed", ver) + } } + + } else if errors.Is(err, ErrUnsupportedVersion) { + log.Debug("User entered VMU alias") + } if err != nil {