/
version.go
79 lines (67 loc) · 2.11 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
69
70
71
72
73
74
75
76
77
78
79
package cmd
import (
"fmt"
"github.com/dory-engine/dorycli/pkg"
"github.com/spf13/cobra"
"net/http"
)
type OptionsVersionRun struct {
*OptionsCommon `yaml:"optionsCommon" json:"optionsCommon" bson:"optionsCommon" validate:""`
}
func NewOptionsVersionRun() *OptionsVersionRun {
var o OptionsVersionRun
o.OptionsCommon = OptCommon
return &o
}
func NewCmdVersion() *cobra.Command {
o := NewOptionsVersionRun()
baseName := pkg.GetCmdBaseName()
msgUse := fmt.Sprintf("version")
_ = OptCommon.GetOptionsCommon()
msgShort := OptCommon.TransLang("cmd_version_short")
msgLong := OptCommon.TransLang("cmd_version_long", baseName)
msgExample := pkg.Indent(OptCommon.TransLang("cmd_version_example", baseName, baseName))
cmd := &cobra.Command{
Use: msgUse,
DisableFlagsInUseLine: true,
Short: msgShort,
Long: msgLong,
Example: msgExample,
Run: func(cmd *cobra.Command, args []string) {
CheckError(o.Complete(cmd))
CheckError(o.Validate(args))
CheckError(o.Run(args))
},
}
return cmd
}
func (o *OptionsVersionRun) Complete(cmd *cobra.Command) error {
var err error
err = o.GetOptionsCommon()
return err
}
func (o *OptionsVersionRun) Validate(args []string) error {
var err error
return err
}
func (o *OptionsVersionRun) Run(args []string) error {
var err error
baseName := pkg.GetCmdBaseName()
fmt.Println(fmt.Sprintf("%s version: %s", baseName, pkg.VersionDoryCli))
fmt.Println(fmt.Sprintf("# install dory-engine version: %s", pkg.VersionDoryEngine))
fmt.Println(fmt.Sprintf("# install dory-console version: %s", pkg.VersionDoryFrontend))
if o.ServerURL != "" {
fmt.Println(fmt.Sprintf("connected Dory-Engine URL: %s", o.ServerURL))
if o.AccessToken != "" {
param := map[string]interface{}{}
result, _, err := o.QueryAPI(fmt.Sprintf("api/public/about"), http.MethodGet, "", param, false)
if err != nil {
return err
}
appInfo := result.Get("data.app").String()
versionInfo := result.Get("data.version").String()
fmt.Println(fmt.Sprintf("connected Dory-Engine version: %s:%s", appInfo, versionInfo))
}
}
return err
}