-
Notifications
You must be signed in to change notification settings - Fork 35
/
version.go
47 lines (41 loc) · 1.02 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
package main
import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/backing-image-manager/pkg/client"
"github.com/longhorn/backing-image-manager/pkg/meta"
"github.com/longhorn/backing-image-manager/pkg/util"
)
func VersionCmd() cli.Command {
return cli.Command{
Name: "version",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "client-only",
},
},
Action: func(c *cli.Context) {
if err := version(c); err != nil {
logrus.Fatalln("Error running info command:", err)
}
},
}
}
type VersionOutput struct {
ClientVersion *meta.VersionOutput `json:"clientVersion"`
ServerVersion *meta.VersionOutput `json:"serverVersion"`
}
func version(c *cli.Context) error {
clientVersion := meta.GetVersion()
v := VersionOutput{ClientVersion: &clientVersion}
if !c.Bool("client-only") {
url := c.GlobalString("url")
cli := client.NewBackingImageManagerClient(url)
version, err := cli.VersionGet()
if err != nil {
return err
}
v.ServerVersion = version
}
return util.PrintJSON(v)
}