-
Notifications
You must be signed in to change notification settings - Fork 150
/
version.go
62 lines (53 loc) · 1.32 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
package main
import (
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/longhorn-engine/pkg/controller/client"
"github.com/longhorn/longhorn-engine/pkg/meta"
)
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")
volumeName := c.GlobalString("volume-name")
engineInstanceName := c.GlobalString("engine-instance-name")
controllerClient, err := client.NewControllerClient(url, volumeName, engineInstanceName)
if err != nil {
return err
}
defer controllerClient.Close()
version, err := controllerClient.VersionDetailGet()
if err != nil {
return err
}
v.ServerVersion = version
}
output, err := json.MarshalIndent(v, "", "\t")
if err != nil {
return err
}
fmt.Println(string(output))
return nil
}