2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1"
25 "github.com/urfave/cli"
28 func initCmdMisc(cmdDef *[]cli.Command) {
29 *cmdDef = append(*cmdDef, cli.Command{
32 Usage: "miscellaneous commands group",
33 Subcommands: []cli.Command{
36 Aliases: []string{"v"},
37 Usage: "Get version of XDS agent and XDS server",
42 Usage: "display verbose output",
48 Aliases: []string{"sts"},
49 Usage: "Get XDS configuration status (including XDS server connection)",
54 Usage: "display verbose output",
62 func xdsVersion(ctx *cli.Context) error {
63 verbose := ctx.Bool("verbose")
66 ver := xaapiv1.XDSVersion{}
67 if err := XdsVersionGet(&ver); err != nil {
68 return cli.NewExitError(err.Error(), 1)
71 writer := NewTableWriter()
72 fmt.Fprintln(writer, "Agent:")
73 fmt.Fprintln(writer, " ID:\t", ver.Client.ID)
74 v := ver.Client.Version
76 v += " (" + ver.Client.VersionGitTag + ")"
78 fmt.Fprintln(writer, " Version:\t", v)
80 fmt.Fprintln(writer, " API Version:\t", ver.Client.APIVersion)
83 for _, svr := range ver.Server {
84 fmt.Fprintln(writer, "Server:")
85 fmt.Fprintln(writer, " ID:\t", svr.ID)
88 v += " (" + svr.VersionGitTag + ")"
90 fmt.Fprintln(writer, " Version:\t", v)
92 fmt.Fprintln(writer, " API Version:\t", svr.APIVersion)
100 func xdsStatus(ctx *cli.Context) error {
101 cfg := xaapiv1.APIConfig{}
102 if err := XdsConfigGet(&cfg); err != nil {
103 return cli.NewExitError(err.Error(), 1)
106 writer := NewTableWriter()
107 fmt.Fprintln(writer, "XDS Server:")
108 for _, svr := range cfg.Servers {
109 fmt.Fprintln(writer, " ID:\t", svr.ID)
110 fmt.Fprintln(writer, " URL:\t", svr.URL)
111 fmt.Fprintln(writer, " Connected:\t", svr.Connected)
112 fmt.Fprintln(writer, " Connection retry:\t", svr.ConnRetry)
113 fmt.Fprintln(writer, " Disabled:\t", svr.Disabled)