Initial commit
[src/xds/xds-cli.git] / cmd-misc.go
1 package main
2
3 import (
4         "fmt"
5
6         "github.com/iotbzh/xds-agent/lib/apiv1"
7         "github.com/urfave/cli"
8 )
9
10 func initCmdMisc(cmdDef *[]cli.Command) {
11         *cmdDef = append(*cmdDef, cli.Command{
12                 Name:     "misc",
13                 HideHelp: true,
14                 Usage:    "miscellaneous commands group",
15                 Subcommands: []cli.Command{
16                         {
17                                 Name:    "version",
18                                 Aliases: []string{"v"},
19                                 Usage:   "Get version of XDS agent and XDS server",
20                                 Action:  xdsVersion,
21                                 Flags: []cli.Flag{
22                                         cli.BoolFlag{
23                                                 Name:  "verbose, v",
24                                                 Usage: "display verbose output",
25                                         },
26                                 },
27                         },
28                 },
29         })
30 }
31
32 func xdsVersion(ctx *cli.Context) error {
33         verbose := ctx.Bool("verbose")
34
35         // Get version
36         ver := apiv1.XDSVersion{}
37         if err := XdsVersionGet(&ver); err != nil {
38                 return cli.NewExitError(err.Error(), 1)
39         }
40
41         writer := NewTableWriter()
42         fmt.Fprintln(writer, "Agent ID:\t", ver.Client.ID)
43         v := ver.Client.Version
44         if verbose {
45                 v += " (" + ver.Client.VersionGitTag + ")"
46         }
47         fmt.Fprintln(writer, "      Version:\t", v)
48         if verbose {
49                 fmt.Fprintln(writer, "      API Version:\t", ver.Client.APIVersion)
50         }
51
52         for _, svr := range ver.Server {
53                 fmt.Fprintln(writer, "Server ID:\t", svr.ID)
54                 v = svr.Version
55                 if verbose {
56                         v += " (" + svr.VersionGitTag + ")"
57                 }
58                 fmt.Fprintln(writer, "       Version:\t", v)
59                 if verbose {
60                         fmt.Fprintln(writer, "       API Version:\t", svr.APIVersion)
61                 }
62         }
63         writer.Flush()
64
65         return nil
66 }