GoPLS Viewer

Home|gopls/cmd/getgo/steps.go
1// Copyright 2017 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build !plan9
6// +build !plan9
7
8package main
9
10import (
11    "context"
12    "fmt"
13    "os"
14    "path/filepath"
15    "runtime"
16    "strings"
17)
18
19type step func(context.Contexterror
20
21func welcome(ctx context.Contexterror {
22    fmt.Println("Welcome to the Go installer!")
23    answererr := prompt(ctx"Would you like to install Go? Y/n""Y")
24    if err != nil {
25        return err
26    }
27    if strings.ToLower(answer) != "y" {
28        fmt.Println("Exiting install.")
29        return errExitCleanly
30    }
31
32    return nil
33}
34
35func checkOthers(ctx context.Contexterror {
36    // TODO: if go is currently installed install new version over that
37    patherr := whichGo(ctx)
38    if err != nil {
39        fmt.Printf("Cannot check if Go is already installed:\n%v\n"err)
40    }
41    if path == "" {
42        return nil
43    }
44    if path != installPath {
45        fmt.Printf("Go is already installed at %v; remove it from your PATH.\n"path)
46    }
47    return nil
48}
49
50func chooseVersion(ctx context.Contexterror {
51    if *goVersion != "" {
52        return nil
53    }
54
55    var err error
56    *goVersionerr = getLatestGoVersion()
57    if err != nil {
58        return err
59    }
60
61    answererr := prompt(ctxfmt.Sprintf("The latest Go version is %s, install that? Y/n", *goVersion), "Y")
62    if err != nil {
63        return err
64    }
65
66    if strings.ToLower(answer) != "y" {
67        // TODO: handle passing a version
68        fmt.Println("Aborting install.")
69        return errExitCleanly
70    }
71
72    return nil
73}
74
75func downloadGo(ctx context.Contexterror {
76    answererr := prompt(ctxfmt.Sprintf("Download Go version %s to %s? Y/n", *goVersioninstallPath), "Y")
77    if err != nil {
78        return err
79    }
80
81    if strings.ToLower(answer) != "y" {
82        fmt.Println("Aborting install.")
83        return errExitCleanly
84    }
85
86    fmt.Printf("Downloading Go version %s to %s\n", *goVersioninstallPath)
87    fmt.Println("This may take a bit of time...")
88
89    if err := downloadGoVersion(*goVersionruntime.GOOSarchinstallPath); err != nil {
90        return err
91    }
92
93    if err := appendToPATH(filepath.Join(installPath"bin")); err != nil {
94        return err
95    }
96
97    fmt.Println("Downloaded!")
98    return nil
99}
100
101func setupGOPATH(ctx context.Contexterror {
102    answererr := prompt(ctx"Would you like us to setup your GOPATH? Y/n""Y")
103    if err != nil {
104        return err
105    }
106
107    if strings.ToLower(answer) != "y" {
108        fmt.Println("Exiting and not setting up GOPATH.")
109        return errExitCleanly
110    }
111
112    fmt.Println("Setting up GOPATH")
113    homeerr := getHomeDir()
114    if err != nil {
115        return err
116    }
117
118    gopath := os.Getenv("GOPATH")
119    if gopath == "" {
120        // set $GOPATH
121        gopath = filepath.Join(home"go")
122        if err := persistEnvVar("GOPATH"gopath); err != nil {
123            return err
124        }
125        fmt.Println("GOPATH has been set up!")
126    } else {
127        verbosef("GOPATH is already set to %s"gopath)
128    }
129
130    if err := appendToPATH(filepath.Join(gopath"bin")); err != nil {
131        return err
132    }
133    return persistEnvChangesForSession()
134}
135
MembersX
welcome
downloadGo
setupGOPATH.home
welcome.err
checkOthers.ctx
chooseVersion
chooseVersion.ctx
chooseVersion.err
downloadGo.ctx
downloadGo.answer
downloadGo.err
setupGOPATH.err
setupGOPATH.gopath
setupGOPATH.BlockStmt.err
step
welcome.ctx
welcome.answer
checkOthers
checkOthers.path
checkOthers.err
chooseVersion.answer
setupGOPATH
setupGOPATH.ctx
setupGOPATH.answer
Members
X