-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.go
52 lines (43 loc) · 1.16 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
package cmd
import (
"fmt"
"github.com/jiaozifs/jiaozifs/api"
"github.com/jiaozifs/jiaozifs/version"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "version of jiaozifs",
Long: `jiaozifs version`,
RunE: func(cmd *cobra.Command, args []string) error {
swagger, err := api.GetSwagger()
if err != nil {
return err
}
fmt.Println("Version ", version.UserVersion())
fmt.Println("API Version ", swagger.Info.Version)
client, err := GetDefaultClient()
if err != nil {
return err
}
versionResp, err := client.GetVersion(cmd.Context())
if err != nil {
return err
}
okResp, err := api.ParseGetVersionResponse(versionResp)
if err != nil {
return err
}
if okResp.JSON200 == nil {
return fmt.Errorf("request version fail %d %s", okResp.HTTPResponse.StatusCode, okResp.HTTPResponse.Body)
}
fmt.Println("Runtime Version ", okResp.JSON200.Version)
fmt.Println("Runtime API Version ", okResp.JSON200.ApiVersion)
fmt.Println("LatestVersion Version ", okResp.JSON200.LatestVersion)
return nil
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}