-
Notifications
You must be signed in to change notification settings - Fork 1k
/
version.go
49 lines (44 loc) · 958 Bytes
/
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
package main
import (
"fmt"
"github.com/cri-o/cri-o/internal/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
const (
jsonFlag = "json"
verboseFlag = "verbose"
)
var versionCommand = &cli.Command{
Name: "version",
Usage: "display detailed version information",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: jsonFlag,
Aliases: []string{"j"},
Usage: "print JSON instead of text",
},
&cli.BoolFlag{
Name: verboseFlag,
Aliases: []string{"v"},
Usage: "print verbose information (for example all golang dependencies)",
},
},
Action: func(c *cli.Context) error {
verbose := c.Bool(verboseFlag)
v, err := version.Get(verbose)
if err != nil {
logrus.Fatal(err)
}
res := v.String()
if c.Bool(jsonFlag) {
j, err := v.JSONString()
if err != nil {
return fmt.Errorf("unable to generate JSON from version info: %w", err)
}
res = j
}
fmt.Println(res)
return nil
},
}