File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "bufio"
45 "fmt"
56 "io/ioutil"
67 "log"
@@ -56,11 +57,23 @@ func getEnvGoVersion() string {
5657 if err != nil {
5758 log .Fatalf ("Unable to run the go command, is it installed?\n Error: %s" , err .Error ())
5859 }
59- goVersion = strings . Fields (string (gover ))[ 2 ]
60+ goVersion = parseGoVersion (string (gover ))
6061 }
6162 return goVersion
6263}
6364
65+ // The 'go version' command may output warnings on separate lines before
66+ // the actual version string is printed. This function parses the output
67+ // to retrieve just the version string.
68+ func parseGoVersion (data string ) string {
69+ var lastLine string
70+ sc := bufio .NewScanner (strings .NewReader (data ))
71+ for sc .Scan () {
72+ lastLine = sc .Text ()
73+ }
74+ return strings .Fields (lastLine )[2 ]
75+ }
76+
6477// Returns the current Go version in semver format, e.g. v1.14.4
6578func getEnvGoSemVer () string {
6679 goVersion := getEnvGoVersion ()
You can’t perform that action at this time.
0 commit comments