Skip to content

Commit

Permalink
trying to add mach aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed Mar 28, 2024
1 parent bd1d40d commit c657f57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 23 additions & 5 deletions cli/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c657f57

Please sign in to comment.