MCPcopy Create free account
hub / github.com/Melkeydev/govm / InstallVersion

Function InstallVersion

internal/cli/cli.go:13–50  ·  view source on GitHub ↗
(version string)

Source from the content-addressed store, hash-verified

11)
12
13func InstallVersion(version string) {
14 fmt.Printf("🔍 Looking for Go version matching %s...\n", version)
15 matchedVersion, err := findMatchingVersion(version)
16 if err != nil {
17 fmt.Printf("❌ %s\n", err)
18 return
19 }
20 fmt.Printf("📥 Installing Go %s...\n", matchedVersion.Version)
21 done := make(chan bool)
22 errCh := make(chan error)
23 go func() {
24 msg := utils.DownloadAndInstall(matchedVersion)()
25 switch msg := msg.(type) {
26 case utils.ErrMsg:
27 errCh <- msg
28 case utils.DownloadCompleteMsg:
29 done <- true
30 }
31 }()
32 spinChars := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
33 spinIdx := 0
34 ticker := time.NewTicker(100 * time.Millisecond)
35 defer ticker.Stop()
36 for {
37 select {
38 case <-done:
39 fmt.Printf("\r✅ Successfully installed Go %s\n", matchedVersion.Version)
40 fmt.Printf("👉 To activate this version, run: govm use %s\n", matchedVersion.Version)
41 return
42 case err := <-errCh:
43 fmt.Printf("\r❌ Installation failed: %v\n", err)
44 return
45 case <-ticker.C:
46 fmt.Printf("\r%s Installing Go %s...", spinChars[spinIdx], matchedVersion.Version)
47 spinIdx = (spinIdx + 1) % len(spinChars)
48 }
49 }
50}
51func UseVersion(version string) {
52 fmt.Printf("🔍 Looking for installed Go version matching %s...\n", version)
53 matchedVersion, err := findInstalledVersion(version)

Callers 1

handleCommandLineFunction · 0.92

Calls 2

DownloadAndInstallFunction · 0.92
findMatchingVersionFunction · 0.85

Tested by

no test coverage detected