mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/getgo: prompt warning if an earlier installation exists
There is nothing else we can do other than just showing a message that user need to remove it from their PATH not to conflict with the current installation. Fixes #21217. Change-Id: Ie65385f4d536d5bb789387ba0229f54f2ee793f0 Reviewed-on: https://go-review.googlesource.com/51930 Run-TryBot: Jaana Burcu Dogan <jbd@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Kevin Burke <kev@inburke.com>
This commit is contained in:
parent
6fdd948b81
commit
9badcbe49b
@ -50,6 +50,7 @@ func main() {
|
||||
|
||||
if !*setupOnly {
|
||||
runStep(welcome)
|
||||
runStep(checkOthers)
|
||||
runStep(chooseVersion)
|
||||
runStep(downloadGo)
|
||||
}
|
||||
|
@ -29,10 +29,22 @@ func welcome(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func chooseVersion(ctx context.Context) error {
|
||||
// TODO: check if go is currently installed
|
||||
func checkOthers(ctx context.Context) error {
|
||||
// TODO: if go is currently installed install new version over that
|
||||
path, err := whichGo(ctx)
|
||||
if err != nil {
|
||||
fmt.Printf("Cannot check if Go is already installed:\n%v\n", err)
|
||||
}
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
if path != installPath {
|
||||
fmt.Printf("Go is already installed at %v; remove it from your PATH.\n", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func chooseVersion(ctx context.Context) error {
|
||||
if *goVersion != "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -6,8 +6,10 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// arch contains either amd64 or 386.
|
||||
@ -27,3 +29,8 @@ var arch = func() string {
|
||||
}
|
||||
return "386"
|
||||
}()
|
||||
|
||||
func findGo(ctx context.Context, cmd string) (string, error) {
|
||||
out, err := exec.CommandContext(ctx, cmd, "go").CombinedOutput()
|
||||
return strings.TrimSpace(string(out)), err
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -28,6 +29,10 @@ var installPath = func() string {
|
||||
return filepath.Join(home, ".go")
|
||||
}()
|
||||
|
||||
func whichGo(ctx context.Context) (string, error) {
|
||||
return findGo(ctx, "which")
|
||||
}
|
||||
|
||||
func isWindowsXP() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"syscall"
|
||||
@ -31,6 +32,10 @@ func isWindowsXP() bool {
|
||||
return major < 6
|
||||
}
|
||||
|
||||
func whichGo(ctx context.Context) (string, error) {
|
||||
return findGo(ctx, "where")
|
||||
}
|
||||
|
||||
// currentShell reports the current shell.
|
||||
// It might be "powershell.exe", "cmd.exe" or any of the *nix shells.
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user