diff --git a/cli/config.go b/cli/config.go index 2d6dab0..3c3c420 100644 --- a/cli/config.go +++ b/cli/config.go @@ -86,16 +86,17 @@ type zigVersion = map[string]any type ZigOnlVersion = map[string][]map[string]string -// func (z *ZVM) loadVersionCache() error { -// ver, err := os.ReadFile(filepath.Join(z.zvmBaseDir, "versions.json")) -// if err != nil { -// return err -// } -// if err := json.Unmarshal(ver, &z.zigVersions); err != nil { -// return err -// } -// return nil -// } +// func (z *ZVM) loadVersionCache() error { +// ver, err := os.ReadFile(filepath.Join(z.zvmBaseDir, "versions.json")) +// if err != nil { +// return err +// } +// if err := json.Unmarshal(ver, &z.zigVersions); err != nil { +// return err +// } +// 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" diff --git a/cli/install.go b/cli/install.go index 59a1c7a..4bf3cea 100644 --- a/cli/install.go +++ b/cli/install.go @@ -197,59 +197,58 @@ func (z *ZVM) Install(version string) error { return nil } func requestWithMirror(tarURL string) (*http.Response, error) { - log.Debug("requestWithMirror", "tarURL", tarURL) + log.Debug("requestWithMirror", "tarURL", tarURL) - tarResp, err := attemptDownload(tarURL) - if err != nil { - return nil, err - } + tarResp, err := attemptDownload(tarURL) + if err != nil { + return nil, err + } - if tarResp.StatusCode == 200 { - return tarResp, nil - } + if tarResp.StatusCode == 200 { + return tarResp, nil + } - mirrors := []func(string) (string, error){mirrorHryx, mirrorMachEngine} + mirrors := []func(string) (string, error){mirrorHryx, mirrorMachEngine} - for i, mirror := range mirrors { - log.Debugf("requestWithMirror url #%d", i) + for i, mirror := range mirrors { + log.Debugf("requestWithMirror url #%d", i) - newURL, err := mirror(tarURL) - if err != nil { - return nil, fmt.Errorf("%w: %w", ErrDownloadFail, err) - } + newURL, err := mirror(tarURL) + if err != nil { + return nil, fmt.Errorf("%w: %w", ErrDownloadFail, err) + } - log.Debug(fmt.Sprintf("mirror %d", i), "url", newURL) + log.Debug(fmt.Sprintf("mirror %d", i), "url", newURL) - tarResp, err = attemptDownload(newURL) - if err != nil { - continue - } + tarResp, err = attemptDownload(newURL) + if err != nil { + continue + } - if tarResp.StatusCode == 200 { - return tarResp, nil - } - } + if tarResp.StatusCode == 200 { + return tarResp, nil + } + } - return nil, errors.Join(err, fmt.Errorf("all download attempts failed")) + return nil, errors.Join(err, fmt.Errorf("all download attempts failed")) } func attemptDownload(url string) (*http.Response, error) { - req, err := createDownloadReq(url) - if err != nil { - return nil, err - } + req, err := createDownloadReq(url) + if err != nil { + return nil, err + } - resp, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } - log.Debug("requestWithMirror", "status code", resp.StatusCode) + log.Debug("requestWithMirror", "status code", resp.StatusCode) - return resp, nil + return resp, nil } - func createDownloadReq(tarURL string) (*http.Request, error) { zigArch, zigOS := zigStyleSysInfo() diff --git a/cli/install_test.go b/cli/install_test.go index 0a94d06..40e9e2c 100644 --- a/cli/install_test.go +++ b/cli/install_test.go @@ -60,24 +60,23 @@ func TestMirrors(t *testing.T) { tarURL := "https://ziglang.org/builds/zig-linux-x86_64-0.14.0-dev.1550+4fba7336a.tar.xz" mirrors := []func(string) (string, error){mirrorHryx, mirrorMachEngine} - for i, mirror := range mirrors { - t.Logf("requestWithMirror url #%d", i) + for i, mirror := range mirrors { + t.Logf("requestWithMirror url #%d", i) + newURL, err := mirror(tarURL) + if err != nil { + t.Errorf("%q: %q", ErrDownloadFail, err) + } - newURL, err := mirror(tarURL) - if err != nil { - t.Errorf("%q: %q", ErrDownloadFail, err) - } + t.Logf("mirror %d; url: %s", i, newURL) - t.Logf("mirror %d; url: %s", i, newURL) + tarResp, err := attemptDownload(newURL) + if err != nil { + continue + } - tarResp, err := attemptDownload(newURL) - if err != nil { - continue - } - - if tarResp.StatusCode != 200 { - t.Fail() - } - } -} \ No newline at end of file + if tarResp.StatusCode != 200 { + t.Fail() + } + } +} diff --git a/cli/meta/cta.go b/cli/meta/cta.go index 861e702..e0b66fe 100644 --- a/cli/meta/cta.go +++ b/cli/meta/cta.go @@ -59,5 +59,5 @@ func CtaUpgradeAvailable(tag string) { Foreground(lipgloss.Color("#fee12b")) fmt.Printf("\nZVM %s is available. You are currently on %s.\n\nRun %s or download the latest release at\n%s\n\n", blueLink.Render(tag), blueLink.Render(VERSION), yellowText.Render("zvm upgrade"), blueLink.Render("https://github.com/tristanisham/zvm/releases/latest")) - + } diff --git a/cli/meta/errors.go b/cli/meta/errors.go index bfa0ce8..ddc894d 100644 --- a/cli/meta/errors.go +++ b/cli/meta/errors.go @@ -6,6 +6,6 @@ package meta import "errors" var ( - ErrWinEscToAdmin = errors.New("unable to rerun as Windows Administrator") + ErrWinEscToAdmin = errors.New("unable to rerun as Windows Administrator") ErrEscalatedSymlink = errors.New("unable to symlink as Administrator") -) \ No newline at end of file +) diff --git a/cli/meta/version.go b/cli/meta/version.go index b9e1e50..b018903 100644 --- a/cli/meta/version.go +++ b/cli/meta/version.go @@ -9,13 +9,11 @@ import ( ) const ( - VERSION = "v0.7.4" + VERSION = "v0.7.5" // VERSION = "v0.0.0" // For testing zvm upgrade ) - var ( VerCopy = fmt.Sprintf("%s %s/%s", VERSION, runtime.GOOS, runtime.GOARCH) ) -