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",
55 Aliases: []string{"ls"},
56 Usage: "List installed SDKs",
61 Usage: "display verbose output",
67 Aliases: []string{"rm"},
68 Usage: "Remove an existing SDK",
81 func sdksList(ctx *cli.Context) error {
83 sdks := []xaapiv1.SDK{}
84 if err := sdksListGet(&sdks); err != nil {
85 return cli.NewExitError(err.Error(), 1)
87 _displaySdks(sdks, ctx.Bool("verbose"))
91 func sdksGet(ctx *cli.Context) error {
94 return cli.NewExitError("id parameter or option must be set", 1)
97 url := "servers/" + strconv.Itoa(XdsServerIndexGet()) + "/sdks/" + id
98 if err := HTTPCli.Get(url, &sdks); err != nil {
99 return cli.NewExitError(err.Error(), 1)
101 _displaySdks([]xaapiv1.SDK{sdks}, true)
105 func _displaySdks(sdks []xaapiv1.SDK, verbose bool) {
108 writer := NewTableWriter()
109 for _, s := range sdks {
114 fmt.Fprintln(writer, "ID\t"+s.ID)
115 fmt.Fprintln(writer, "Name\t"+s.Name)
116 fmt.Fprintln(writer, "Profile\t"+s.Profile)
117 fmt.Fprintln(writer, "Arch\t"+s.Arch)
118 fmt.Fprintln(writer, "Version\t"+s.Version)
119 fmt.Fprintln(writer, "Path\t"+s.Path)
123 fmt.Fprintf(writer, "List of installed SDKs: \n")
124 fmt.Fprintf(writer, " ID\tNAME\n")
126 fmt.Fprintf(writer, " %s\t%s\n", s.ID, s.Name)
133 func sdksListGet(sdks *[]xaapiv1.SDK) error {
134 url := "servers/" + strconv.Itoa(XdsServerIndexGet()) + "/sdks"
135 if err := HTTPCli.Get(url, &sdks); err != nil {
138 Log.Debugf("Result of %s: %v", url, sdks)
143 func sdksAdd(ctx *cli.Context) error {
144 return fmt.Errorf("not supported yet")
147 func sdksRemove(ctx *cli.Context) error {
150 return cli.NewExitError("id parameter or option must be set", 1)
153 return fmt.Errorf("not supported yet")