/
version_cmd.go
73 lines (61 loc) · 1.7 KB
/
version_cmd.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"fmt"
"runtime"
"runtime/debug"
)
// $kddp version provides information about the version of the used kddp build
type VersionCommand struct {
fs *flag.FlagSet
verbose bool
build_info bool
}
func NewVersionCommand() *VersionCommand {
return &VersionCommand{
fs: flag.NewFlagSet("version", flag.ExitOnError),
verbose: false,
build_info: false,
}
}
func (cmd *VersionCommand) Init(args []string) error {
cmd.fs.BoolVar(&cmd.verbose, "wortreich", cmd.verbose, "Zeige wortreiche Informationen")
cmd.fs.BoolVar(&cmd.build_info, "go_build_info", cmd.build_info, "Zeige Go build Informationen")
return parseFlagSet(cmd.fs, args)
}
var (
DDPVERSION string = "undefined"
LLVMVERSION string = "undefined"
GCCVERSION string = "undefined"
GCCVERSIONFULL string = "undefined"
)
func (cmd *VersionCommand) Run() error {
fmt.Printf("%s %s %s\n", DDPVERSION, runtime.GOOS, runtime.GOARCH)
if bi, ok := debug.ReadBuildInfo(); ok {
if cmd.verbose {
fmt.Printf("Go Version: %s\n", bi.GoVersion)
}
if cmd.build_info {
fmt.Printf("Go build info:\n")
for _, v := range bi.Settings {
fmt.Printf("%s: %s\n", v.Key, v.Value)
}
}
} else if cmd.verbose {
fmt.Printf("Go Version: undefined\n")
}
if cmd.verbose {
fmt.Printf("GCC Version: %s ; Full: %s\n", GCCVERSION, GCCVERSIONFULL)
fmt.Printf("LLVM Version: %s\n", LLVMVERSION)
}
return nil
}
func (cmd *VersionCommand) Name() string {
return cmd.fs.Name()
}
func (cmd *VersionCommand) Usage() string {
return `version <Optionen>: Zeige informationen zu dieser DDP Version
Optionen:
--wortreich: Zeige wortreiche Informationen
--go_build_info: Zeige Go build Informationen`
}