Pierre Curto %!s(int64=6) %!d(string=hai) anos
pai
achega
a29bec8a92

+ 14 - 0
internal/cmdflag/buildinfo.go

@@ -0,0 +1,14 @@
+// +build go1.12
+
+package cmdflag
+
+import (
+	"runtime/debug"
+)
+
+func buildinfo() string {
+	if bi, ok := debug.ReadBuildInfo(); ok {
+		return bi.Main.Version
+	}
+	return "no version available (not built with module support)"
+}

+ 7 - 0
internal/cmdflag/buildinfo_lt_1_12.go

@@ -0,0 +1,7 @@
+// +build !go1.12
+
+package cmdflag
+
+func buildinfo() string {
+	return "no version available"
+}

+ 3 - 7
internal/cmdflag/cmdflag.go

@@ -8,7 +8,6 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
-	"runtime/debug"
 	"strings"
 	"sync"
 )
@@ -111,12 +110,9 @@ func Parse() error {
 			if b, ok := v.Get().(bool); ok && b {
 				// The flag was defined as a bool and is set.
 				program := programName(args[0])
-				if bi, ok := debug.ReadBuildInfo(); ok {
-					fmt.Fprintf(out, "%s version %s", program, bi.Main.Version)
-				} else {
-					fmt.Fprintf(out, "%s no version available (not built with module support)", program)
-				}
-				fmt.Fprintf(out, " %s/%s\n", runtime.GOOS, runtime.GOARCH)
+				fmt.Fprintf(out, "%s version %s %s/%s\n",
+					program, buildinfo(),
+					runtime.GOOS, runtime.GOARCH)
 				return nil
 			}
 		}