-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
63 lines (53 loc) · 1.27 KB
/
get.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
)
var getCommands = []cli.Command{
cli.Command{
Name: "apps",
Aliases: []string{"app"},
Usage: "Get application details",
UsageText: "get apps [UUID]",
Action: GetApplication,
},
}
// GetApplication retrieves a list of applications
func GetApplication(c *cli.Context) error {
uuid := c.Args().Get(0)
if uuid == "" {
return errors.New(c.Command.UsageText)
}
type environment struct {
Name string `json:"name"`
UUID string `json:"uuid"`
}
type appDetails struct {
Name string `json:"name"`
UUID string `json:"uuid"`
Environments []environment `json:"environments"`
}
body, err := HTTPGet("/api/v1/applications/" + uuid)
if err != nil {
return err
}
var app appDetails
err = json.Unmarshal([]byte(body), &app)
if err != nil {
return errors.New("Unable to read JSON response.")
}
fmt.Println("Name: " + app.Name)
fmt.Println("UUID: " + app.UUID)
table := tablewriter.NewWriter(os.Stdout)
fmt.Println("\nEnvironments")
table.SetHeader([]string{"Name", "UUID"})
for _, env := range app.Environments {
table.Append([]string{env.Name, env.UUID})
}
table.Render()
return nil
}