diff --git a/.golangci.yaml b/.golangci.yaml index fe58133..73b98f1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -12,7 +12,7 @@ linters: - staticcheck - dupl - errorlint - - exportloopref + - copyloopvar - goconst - gocritic - gocyclo diff --git a/README.md b/README.md index f780cc5..fb42ed9 100644 --- a/README.md +++ b/README.md @@ -357,27 +357,28 @@ export GOPATH="$HOME/.gobrew/current/go" # MAJOR CHANGE LOG -- v1.2.0 - Added rc|beta versions, appended at the end of list -- v1.5.0 - Mac M1 support -- v1.5.5 - arm|M1|darwin support added -- v1.5.8 - Show download progress and use Go's compression instead of tar command -- v1.6.0 - Added support for @latest and @dev-latest and progress bar for download -- v1.6.2 - Using goreleaser #35 by @juev -- v1.6.3 - Added latest and dev-latest -- v1.6.4 - Github action publish -- v1.6.7 - Fixes rate limit issue -- v1.7.4 - Added 2 new options `gobrew version` and `gobrew prune` -- v1.7.5 - Fixes strange output on `gobrew use latest` -- v1.7.8 - Windows support, self-update fixes -- v1.7.9 - Windows fix ups and bash-completions -- v1.8.0 - Windows support, including actions -- v1.8.4 - Light background terminal support -- v1.8.6 - Fixes where 1.20.0 was detected as 1.20 -- v1.9.0 - v1.8.6 ~ v1.9.0, updates colors packages, fixes UT issues for Github status codes -- v1.9.4 - `gobrew` interactive -- v1.9.8 - bug fix where 1.21 is not detected as 1.21.0 -- v1.10.10 - `ls-remote` is blazing fast, cached. -- v1.10.11 - Optional options for cache and ttl. +- **v1.2.0** - Added rc|beta versions, appended at the end of list +- **v1.5.0** - Mac M1 support +- **v1.5.5** - arm|M1|darwin support added +- **v1.5.8** - Show download progress and use Go's compression instead of tar command +- **v1.6.0** - Added support for @latest and @dev-latest and progress bar for download +- **v1.6.2** - Using goreleaser #35 by @juev +- **v1.6.3** - Added latest and dev-latest +- **v1.6.4** - Github action publish +- **v1.6.7** - Fixes rate limit issue +- **v1.7.4** - Added 2 new options `gobrew version` and `gobrew prune` +- **v1.7.5** - Fixes strange output on `gobrew use latest` +- **v1.7.8** - Windows support, self-update fixes +- **v1.7.9** - Windows fix ups and bash-completions +- **v1.8.0** - Windows support, including actions +- **v1.8.4** - Light background terminal support +- **v1.8.6** - Fixes where 1.20.0 was detected as 1.20 +- **v1.9.0** - v1.8.6 ~ v1.9.0, updates colors packages, fixes UT issues for Github status codes +- **v1.9.4** - `gobrew` interactive +- **v1.9.8** - bug fix where 1.21 is not detected as 1.21.0 +- **v1.10.10** - `ls-remote` is blazing fast, cached. +- **v1.10.11** - Optional options for cache and ttl. +- **v1.10.12** - Icons on `gobrew` and install command. # DEVELOPMENT NOTES diff --git a/gobrew.go b/gobrew.go index 9bddf47..e5cb1ee 100644 --- a/gobrew.go +++ b/gobrew.go @@ -114,31 +114,33 @@ func (gb *GoBrew) Interactive(ask bool) { fmt.Println() if currentVersion == NoneVersion { - color.Warnln("GO Installed Version", ".......", currentVersion) + color.Warnln("🚨 Installed Version", ".......", currentVersion, "⚠️") } else { var labels []string if modVersion != NoneVersion && currentMajorVersion != modVersion { - labels = append(labels, "not same as go.mod") + labels = append(labels, "🔄 not same as go.mod") } if currentVersion != latestVersion { - labels = append(labels, "not latest") + labels = append(labels, "⬆️ not latest") } label := "" if len(labels) > 0 { - label = "(" + strings.Join(labels, ", ") + ")" label = " " + color.FgRed.Render(label) } - color.Successln("GO Installed Version", ".......", currentVersion+label) + if currentVersion != latestVersion { + color.Successln("✅ Installed Version", ".......", currentVersion+label, "\t🌟", latestVersion, "available") + } else { + color.Successln("✅ Installed Version", ".......", currentVersion+label, "\t🎉", "on latest") + } } if modVersion != NoneVersion && latestMajorVersion != modVersion { - label := " " + color.FgYellow.Render("(not latest)") - color.Successln("GO go.mod Version", " .......", modVersion+label) + label := " " + color.FgYellow.Render("\t⚠️ not latest") + color.Successln("📄 go.mod Version", " .......", modVersion+label) } else { - color.Successln("GO go.mod Version", " .......", modVersion) + color.Successln("📄 go.mod Version", " .......", modVersion) } - color.Successln("GO Latest Version", " .......", latestVersion) fmt.Println() if currentVersion == NoneVersion { @@ -154,10 +156,11 @@ func (gb *GoBrew) Interactive(ask bool) { } if modVersion != NoneVersion && currentMajorVersion != modVersion { - color.Warnf("GO Installed Version (%s) and go.mod Version (%s) are different.\n", currentMajorVersion, modVersion) + color.Warnf("⚠️ GO Installed Version (%s) and go.mod Version (%s) are different.\n", currentMajorVersion, modVersion) + fmt.Println(" Please consider updating your go.mod file") c := true if ask { - c = askForConfirmation("Do you want to use GO version same as go.mod version (" + modVersion + "@latest)?") + c = askForConfirmation("🤔 Do you want to use GO version same as go.mod version (" + modVersion + "@latest)?") } if c { gb.Use(modVersion + "@latest") @@ -166,10 +169,10 @@ func (gb *GoBrew) Interactive(ask bool) { } if currentVersion != latestVersion { - color.Warnf("GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion) + color.Warnf("⚠️ GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion) c := true if ask { - c = askForConfirmation("Do you want to update GO to latest version (" + latestVersion + ")?") + c = askForConfirmation("🤔 Do you want to update GO to latest version (" + latestVersion + ")?") } if c { gb.Use(latestVersion) @@ -272,8 +275,8 @@ func (gb *GoBrew) ListVersions() { } // ListRemoteVersions that are installed by dir ls -func (gb *GoBrew) ListRemoteVersions(print bool) map[string][]string { - if print { +func (gb *GoBrew) ListRemoteVersions(shouldPrint bool) map[string][]string { + if shouldPrint { color.Infoln("==> [Info] Fetching remote versions") } tags := gb.getGolangVersions() @@ -281,7 +284,7 @@ func (gb *GoBrew) ListRemoteVersions(print bool) map[string][]string { var versions []string versions = append(versions, tags...) - return gb.getGroupedVersion(versions, print) + return gb.getGroupedVersion(versions, shouldPrint) } // CurrentVersion get current version from symb link diff --git a/helpers.go b/helpers.go index 4cf23d7..aa20180 100644 --- a/helpers.go +++ b/helpers.go @@ -41,7 +41,7 @@ func (gb *GoBrew) getArch() string { return runtime.GOOS + "-" + runtime.GOARCH } -func (gb *GoBrew) getGroupedVersion(versions []string, print bool) map[string][]string { +func (gb *GoBrew) getGroupedVersion(versions []string, shouldPrint bool) map[string][]string { groupedVersions := make(map[string][]string) for _, version := range versions { parts := strings.Split(version, ".") @@ -88,15 +88,15 @@ func (gb *GoBrew) getGroupedVersion(versions []string, print bool) map[string][] lookupKey = versionParts[0] + "." + versionParts[1] // On match 1.0.0, print 1. On match 2.0.0 print 2 if reTopVersion.MatchString(strKey) { - if print { + if shouldPrint { color.Infop(versionParts[0]) } - gb.print("\t", print) + gb.print("\t", shouldPrint) } else { - if print { + if shouldPrint { color.Successp(lookupKey) } - gb.print("\t", print) + gb.print("\t", shouldPrint) } groupedVersionsSemantic := make([]*semver.Version, 0) @@ -112,29 +112,29 @@ func (gb *GoBrew) getGroupedVersion(versions []string, print bool) map[string][] maxPerLine++ if maxPerLine == 6 { maxPerLine = 0 - gb.print("\n\t", print) + gb.print("\n\t", shouldPrint) } - gb.print(gvSemantic.String()+" ", print) + gb.print(gvSemantic.String()+" ", shouldPrint) } maxPerLine = 0 - gb.print("\n\t", print) + gb.print("\n\t", shouldPrint) // print rc and beta versions in the end for _, rcVersion := range groupedVersions[lookupKey] { r := regexp.MustCompile("beta.*|rc.*") matches := r.FindAllString(rcVersion, -1) if len(matches) == 1 { - gb.print(rcVersion+" ", print) + gb.print(rcVersion+" ", shouldPrint) maxPerLine++ if maxPerLine == 6 { maxPerLine = 0 - gb.print("\n\t", print) + gb.print("\n\t", shouldPrint) } } } - gb.print("\n", print) - gb.print("\n", print) + gb.print("\n", shouldPrint) + gb.print("\n", shouldPrint) } return groupedVersions } @@ -503,8 +503,8 @@ func askForConfirmation(s string) bool { reader := bufio.NewReader(os.Stdin) for { - fmt.Printf("%s ", s) - color.Successf("[y/n]: ") + color.Successf(s) // nolint:govet + fmt.Print(" [y/n]: ") response, err := reader.ReadString('\n') if err != nil { diff --git a/helpers_test.go b/helpers_test.go index 61f6763..ddf2134 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -58,7 +58,6 @@ func TestJudgeVersion(t *testing.T) { // }, } for _, test := range tests { - test := test t.Run(test.version, func(t *testing.T) { t.Parallel() ts := httptest.NewServer(http.FileServer(http.Dir("testdata"))) @@ -140,7 +139,6 @@ func TestExtractMajorVersion(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() if got := extractMajorVersion(tt.args.version); got != tt.want { @@ -180,7 +178,6 @@ func TestGoBrew_extract(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() ts := httptest.NewServer(http.FileServer(http.Dir("testdata"))) @@ -213,7 +210,6 @@ func Test_doRequest(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))