-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"fmt"
"html/template"
"os"
"runtime"
)
var (
gitVersion = "v0.0.0"
gitCommit = "$Format:%H$"
printVersion = false
)
const versionTemplate = `Git version: {{.GitVersion}}
Git commit: {{.GitCommit}}
Go version: {{.GoVersion}}
Compiler: {{.Compiler}}
Platform: {{.Platform}}
`
func main() {
flag.BoolVar(&printVersion, "version", printVersion, "Print version and exit")
flag.Parse()
if printVersion {
tmpl := template.Must(template.New("").Parse(versionTemplate))
if err := tmpl.Execute(os.Stderr, struct {
GitVersion string
GitCommit string
GoVersion string
Compiler string
Platform string
}{
GitVersion: gitVersion,
GitCommit: gitCommit,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}); err != nil {
panic(err)
}
os.Exit(1)
}
arg := "World"
if flag.Arg(0) != "" {
arg = flag.Arg(0)
}
fmt.Printf("Hello %s\n", arg)
}