forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
61 lines (48 loc) · 1.19 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
package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
cli "github.com/lxc/lxd/shared/cmd"
"github.com/lxc/lxd/shared/i18n"
"github.com/lxc/lxd/shared/version"
)
type cmdVersion struct {
global *cmdGlobal
}
func (c *cmdVersion) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("version", i18n.G("[<remote>:]"))
cmd.Short = i18n.G("Show local and remote versions")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Show local and remote versions`))
cmd.RunE = c.Run
return cmd
}
func (c *cmdVersion) Run(cmd *cobra.Command, args []string) error {
// Quick checks.
exit, err := c.global.CheckArgs(cmd, args, 0, 1)
if exit {
return err
}
fmt.Printf(i18n.G("Client version: %s\n"), version.Version)
// Remote version
remote := ""
if len(args) == 1 {
remote = args[0]
if !strings.HasSuffix(remote, ":") {
remote = remote + ":"
}
}
version := i18n.G("unreachable")
resources, err := c.global.ParseServers(remote)
if err == nil {
resource := resources[0]
info, _, err := resource.server.GetServer()
if err == nil {
version = info.Environment.ServerVersion
}
}
fmt.Printf(i18n.G("Server version: %s\n"), version)
return nil
}