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 {
|
if !*setupOnly {
|
||||||
runStep(welcome)
|
runStep(welcome)
|
||||||
|
runStep(checkOthers)
|
||||||
runStep(chooseVersion)
|
runStep(chooseVersion)
|
||||||
runStep(downloadGo)
|
runStep(downloadGo)
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,22 @@ func welcome(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func chooseVersion(ctx context.Context) error {
|
func checkOthers(ctx context.Context) error {
|
||||||
// TODO: check if go is currently installed
|
|
||||||
// TODO: if go is currently installed install new version over that
|
// 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 != "" {
|
if *goVersion != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// arch contains either amd64 or 386.
|
// arch contains either amd64 or 386.
|
||||||
@ -27,3 +29,8 @@ var arch = func() string {
|
|||||||
}
|
}
|
||||||
return "386"
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -28,6 +29,10 @@ var installPath = func() string {
|
|||||||
return filepath.Join(home, ".go")
|
return filepath.Join(home, ".go")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
func whichGo(ctx context.Context) (string, error) {
|
||||||
|
return findGo(ctx, "which")
|
||||||
|
}
|
||||||
|
|
||||||
func isWindowsXP() bool {
|
func isWindowsXP() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -31,6 +32,10 @@ func isWindowsXP() bool {
|
|||||||
return major < 6
|
return major < 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func whichGo(ctx context.Context) (string, error) {
|
||||||
|
return findGo(ctx, "where")
|
||||||
|
}
|
||||||
|
|
||||||
// currentShell reports the current shell.
|
// currentShell reports the current shell.
|
||||||
// It might be "powershell.exe", "cmd.exe" or any of the *nix shells.
|
// It might be "powershell.exe", "cmd.exe" or any of the *nix shells.
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user