Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
govm
main
.idea
2 changes: 1 addition & 1 deletion internal/setup/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ After adding to PATH, restart your terminal or run:
highlightStyle.Render(m.shimPath),
highlightStyle.Render(fmt.Sprintf("echo 'export PATH=\"$HOME/.govm/shim:$PATH\"' >> %s", shellConfigFile)),
shellConfigFile,
highlightStyle.Render(fmt.Sprintf("export PATH=\"$HOME/.govm/shim:$PATH\"")),
highlightStyle.Render("export PATH=\"$HOME/.govm/shim:$PATH\""),
highlightStyle.Render(fmt.Sprintf("source %s", shellConfigFile)))
}

Expand Down
10 changes: 10 additions & 0 deletions internal/utils/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package utils

import "runtime"

type ErrMsg error

type VersionsMsg []GoVersion

type DeleteCompleteMsg struct {
Version string
}

var goBinary = "go"

func init() {
if runtime.GOOS == "windows" {
goBinary = "go.exe"
}
}
14 changes: 8 additions & 6 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"encoding/json"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"io"
"net/http"
"os"
Expand All @@ -13,6 +12,8 @@ import (
"sort"
"strconv"
"strings"

tea "github.com/charmbracelet/bubbletea"
)

type GoVersion struct {
Expand Down Expand Up @@ -123,7 +124,7 @@ func FetchGoVersions() tea.Msg {
if entry.IsDir() && strings.HasPrefix(entry.Name(), "go") {
versionPath := filepath.Join(goVersionsDir, entry.Name())
version := strings.TrimPrefix(entry.Name(), "go")
goBin := filepath.Join(versionPath, "bin", "go")
goBin := filepath.Join(versionPath, "bin", goBinary)
if _, err := os.Stat(goBin); err == nil {
installedVersions[version] = versionPath
}
Expand Down Expand Up @@ -256,18 +257,19 @@ func DownloadAndInstall(version GoVersion) tea.Cmd {
if err != nil {
return ErrMsg(fmt.Errorf("extraction error: %v\nOutput: %s", err, string(output)))
}

if runtime.GOOS != "windows" {
goBin := filepath.Join(versionDir, "bin", "go")
goBin := filepath.Join(versionDir, "bin", goBinary)
if _, err := os.Stat(goBin); err == nil {
os.Chmod(goBin, 0755)
}
}
goBin := filepath.Join(versionDir, "bin", "go")
goBin := filepath.Join(versionDir, "bin", goBinary)
if _, err := os.Stat(goBin); os.IsNotExist(err) {
entries, _ := os.ReadDir(goVersionsDir)
for _, entry := range entries {
if entry.IsDir() && strings.HasPrefix(entry.Name(), "go") {
testPath := filepath.Join(goVersionsDir, entry.Name(), "bin", "go")
testPath := filepath.Join(goVersionsDir, entry.Name(), "bin", goBinary)
if _, err := os.Stat(testPath); err == nil {
sourcePath := filepath.Join(goVersionsDir, entry.Name())
if sourcePath != versionDir {
Expand Down Expand Up @@ -316,7 +318,7 @@ func SwitchVersion(version GoVersion) tea.Cmd {
}
for _, entry := range entries {
if !entry.IsDir() {
binName := entry.Name()
binName := strings.Trim(entry.Name(), ".exe")
targetBin := filepath.Join(versionBinDir, binName)
shimPath := filepath.Join(shimDir, binName)
os.Remove(shimPath)
Expand Down