Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/welcome - nothing major, just icons #213

Merged
merged 9 commits into from
Nov 20, 2024
Merged
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linters:
- staticcheck
- dupl
- errorlint
- exportloopref
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

- copyloopvar
- goconst
- gocritic
- gocyclo
Expand Down
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions gobrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "⚠️")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use UTF-8 characters, how will this work on remote machines? Or where a different code page is used? Didn't check?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't check. UTF8 support should be there on most machines. User can always use gobrew <command>
This PR only effects the gobrew interactive command.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

} 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 {
Expand All @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -272,16 +275,16 @@ 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()

var versions []string
versions = append(versions, tags...)

return gb.getGroupedVersion(versions, print)
return gb.getGroupedVersion(versions, shouldPrint)
}

// CurrentVersion get current version from symb link
Expand Down
28 changes: 14 additions & 14 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ".")
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestJudgeVersion(t *testing.T) {
// },
}
for _, test := range tests {
test := test
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

╰─$ golangci-lint run ./...
helpers_test.go:61:3: The copy of the 'for' variable "test" can be deleted (Go 1.22+) (copyloopvar)
		test := test
		^
helpers_test.go:143:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+) (copyloopvar)
		tt := tt
		^
helpers_test.go:183:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+) (copyloopvar)
		tt := tt
		^
helpers_test.go:216:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+) (copyloopvar)
		tt := tt
		^

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

t.Run(test.version, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")))
Expand Down Expand Up @@ -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")))
Expand Down
Loading