Skip to content

Commit

Permalink
Support when no current version
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Nov 1, 2023
1 parent 7d911bf commit c18716e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gobrew.go
Expand Up @@ -104,7 +104,7 @@ func (gb *GoBrew) Interactive(ask bool) {
color.Warnln("GO Installed Version", ".......", currentVersion)
} else {
labels := []string{}
if currentMajorVersion != modVersion && modVersion != "None" {
if modVersion != "None" && currentMajorVersion != modVersion {
labels = append(labels, "not same as go.mod")
}
if currentVersion != latestVersion {
Expand All @@ -130,11 +130,18 @@ func (gb *GoBrew) Interactive(ask bool) {
color.Successln("GO Latest Version", " .......", latestVersion)
fmt.Println()

// do not implement this yet. gobrew should not tinker with someone's project and edit their go.mod files
// if latestMajorVersion != modVersion {
// color.Yellowf("GO Installed Major Version (%s) and GO Latest Version (%s) are different.\n", currentMajorVersion, latestMajorVersion)
// // do you want to install latest and update go.mod file
// }
if currentVersion == "None" {
color.Warnln("GO is not installed.")
c := true
if ask {
c = AskForConfirmation("Do you want to use latest GO version (" + latestVersion + ")?")
}
if c {
gb.Install(latestVersion)
gb.Use(latestVersion)
}
return
}

if currentMajorVersion != modVersion {
color.Warnf("GO Installed Version (%s) and go.mod Version (%s) are different.\n", currentMajorVersion, modVersion)
Expand All @@ -143,6 +150,7 @@ func (gb *GoBrew) Interactive(ask bool) {
c = AskForConfirmation("Do you want to use GO version same as go.mod version (" + modVersion + "@latest)?")
}
if c {
gb.Install(modVersion + "@latest")
gb.Use(modVersion + "@latest")
}
return
Expand All @@ -155,6 +163,7 @@ func (gb *GoBrew) Interactive(ask bool) {
c = AskForConfirmation("Do you want to update GO to latest version (" + latestVersion + ")?")
}
if c {
gb.Install(latestVersion)
gb.Use(latestVersion)
}
return
Expand Down Expand Up @@ -621,7 +630,7 @@ func (gb *GoBrew) Upgrade(currentVersion string) {
"[Error] Download GoBrew failed")

source, err := os.Open(tmpFile)
utils.CheckError(err, "==> [Error] Cannot open file")
utils.CheckError(err, "[Error] Cannot open file")
defer func(source *os.File) {
_ = source.Close()
utils.CheckError(os.Remove(source.Name()), "==> [Error] Cannot remove tmp file:")
Expand Down
3 changes: 3 additions & 0 deletions helpers.go
Expand Up @@ -12,6 +12,9 @@ import (

func ExtractMajorVersion(version string) string {
parts := strings.Split(version, ".")
if len(parts) < 2 {
return ""
}

// Take the first two parts and join them back with a period to create the new version.
majorVersion := strings.Join(parts[:2], ".")
Expand Down

0 comments on commit c18716e

Please sign in to comment.