2 * Copyright (C) 2017 "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.
25 "github.com/iotbzh/xds-agent/lib/xaapiv1"
26 "github.com/urfave/cli"
29 func initCmdSdks(cmdDef *[]cli.Command) {
30 *cmdDef = append(*cmdDef, cli.Command{
32 Aliases: []string{"sdk"},
34 Usage: "SDKs commands group",
35 Subcommands: []cli.Command{
38 Aliases: []string{"a"},
39 Usage: "Add a new SDK",
44 Usage: "Get a property of a SDK",
56 Aliases: []string{"ls"},
57 Usage: "List installed SDKs",
62 Usage: "display verbose output",
68 Aliases: []string{"rm"},
69 Usage: "Remove an existing SDK",
83 func sdksList(ctx *cli.Context) error {
85 sdks := []xaapiv1.SDK{}
86 if err := sdksListGet(&sdks); err != nil {
87 return cli.NewExitError(err.Error(), 1)
89 _displaySdks(sdks, ctx.Bool("verbose"))
93 func sdksGet(ctx *cli.Context) error {
96 return cli.NewExitError("id parameter or option must be set", 1)
99 url := "servers/" + strconv.Itoa(XdsServerIndexGet()) + "/sdks/" + id
100 if err := HTTPCli.Get(url, &sdks); err != nil {
101 return cli.NewExitError(err.Error(), 1)
103 _displaySdks([]xaapiv1.SDK{sdks}, true)
107 func _displaySdks(sdks []xaapiv1.SDK, verbose bool) {
110 writer := NewTableWriter()
111 for _, s := range sdks {
116 fmt.Fprintln(writer, "ID\t"+s.ID)
117 fmt.Fprintln(writer, "Name\t"+s.Name)
118 fmt.Fprintln(writer, "Profile\t"+s.Profile)
119 fmt.Fprintln(writer, "Arch\t"+s.Arch)
120 fmt.Fprintln(writer, "Version\t"+s.Version)
121 fmt.Fprintln(writer, "Path\t"+s.Path)
125 fmt.Fprintf(writer, "List of installed SDKs: \n")
126 fmt.Fprintf(writer, " ID\tNAME\n")
128 fmt.Fprintf(writer, " %s\t%s\n", s.ID, s.Name)
135 func sdksListGet(sdks *[]xaapiv1.SDK) error {
136 url := "servers/" + strconv.Itoa(XdsServerIndexGet()) + "/sdks"
137 if err := HTTPCli.Get(url, &sdks); err != nil {
140 Log.Debugf("Result of %s: %v", url, sdks)
145 func sdksAdd(ctx *cli.Context) error {
146 return fmt.Errorf("not supported yet")
149 func sdksRemove(ctx *cli.Context) error {
152 return cli.NewExitError("id parameter or option must be set", 1)
155 return fmt.Errorf("not supported yet")