-
Notifications
You must be signed in to change notification settings - Fork 231
/
version.go
68 lines (56 loc) · 1.33 KB
/
version.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
package main
import (
"fmt"
"github.com/genuinetools/img/internal/binutils"
"github.com/genuinetools/img/version"
"github.com/spf13/cobra"
"runtime"
)
const versionHelp = `Show the version information.`
// newVersionCommand creates a command that returns information about the current build
func newVersionCommand() *cobra.Command {
version := &versionCommand{}
cmd := &cobra.Command{
Use: "version",
DisableFlagsInUseLine: true,
SilenceUsage: true,
Short: versionHelp,
Long: versionHelp,
Args: validateHasNoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return version.Run(args)
},
}
return cmd
}
type versionCommand struct{}
func (cmd *versionCommand) Run(args []string) error {
printImgVersion()
printRuncVersion()
return nil
}
func printImgVersion() {
fmt.Printf(`%s:
version : %s
git hash : %s
go version : %s
go compiler : %s
platform : %s/%s
`, "img", version.VERSION, version.GITCOMMIT,
runtime.Version(), runtime.Compiler, runtime.GOOS, runtime.GOARCH)
}
func printRuncVersion() {
v, err := binutils.GetRuncVersion()
if err != nil {
fmt.Printf(`runc:
error: %s
`, err)
return
}
fmt.Printf(`%s:
version : %s
commit : %s
spec : %s
`, "runc", v.Runc, v.Commit,
v.Spec)
}