mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
add support for go1.8 gopath
This commit is contained in:
parent
b787445794
commit
eb14b2049f
1 changed files with 22 additions and 1 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
var cmdDirs = [...]string{"cmd", "cmds", "command", "commands"}
|
||||
|
@ -30,9 +31,29 @@ func init() {
|
|||
// Initialize srcPaths.
|
||||
envGoPath := os.Getenv("GOPATH")
|
||||
goPaths := filepath.SplitList(envGoPath)
|
||||
if len(goPaths) == 0 {
|
||||
// Adapted from https://github.com/Masterminds/glide/pull/798/files.
|
||||
// As of Go 1.8 the GOPATH is no longer required to be set. Instead there
|
||||
// is a default value. If there is no GOPATH check for the default value.
|
||||
// Note, checking the GOPATH first to avoid invoking the go toolchain if
|
||||
// possible.
|
||||
|
||||
goExecutable := os.Getenv("COBRA_GO_EXECUTABLE")
|
||||
if len(goExecutable) <= 0 {
|
||||
goExecutable = "go"
|
||||
}
|
||||
|
||||
out, err := exec.Command(goExecutable, "env", "GOPATH").Output()
|
||||
if err != nil {
|
||||
er(err)
|
||||
}
|
||||
|
||||
toolchainGoPath := strings.TrimSpace(string(out))
|
||||
goPaths = filepath.SplitList(toolchainGoPath)
|
||||
if len(goPaths) == 0 {
|
||||
er("$GOPATH is not set")
|
||||
}
|
||||
}
|
||||
srcPaths = make([]string, 0, len(goPaths))
|
||||
for _, goPath := range goPaths {
|
||||
srcPaths = append(srcPaths, filepath.Join(goPath, "src"))
|
||||
|
|
Loading…
Add table
Reference in a new issue