-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
46 lines (38 loc) · 850 Bytes
/
list.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
package main
import (
"encoding/json"
"errors"
"os"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
)
var listCommands = []cli.Command{
cli.Command{
Name: "apps",
Usage: "list all applications",
Action: ListApplications,
},
}
// ListApplications retrieves a list of applications
func ListApplications(c *cli.Context) error {
type appList struct {
Name string `json:"name"`
UUID string `json:"uuid"`
}
body, err := HTTPGet("/api/v1/applications")
if err != nil {
return err
}
var apps []appList
err = json.Unmarshal([]byte(body), &apps)
if err != nil {
return errors.New("Unable to read JSON response.")
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "UUID"})
for _, app := range apps {
table.Append([]string{app.Name, app.UUID})
}
table.Render()
return nil
}