-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.go
60 lines (51 loc) · 1.32 KB
/
services.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
package cmd
import (
"encoding/json"
"github.com/renderinc/cli/pkg/http"
"github.com/renderinc/cli/pkg/table"
"github.com/spf13/cobra"
)
type Service struct {
Id string `json:"id"`
Type string `json:"type"`
Repo string `json:"repo"`
Name string `json:"name"`
AutoDeploy bool `json:"autoDeploy"`
Branch string `json:"branch"`
CreatedAt string `json:"createdAt"`
NotifyOnFail string `json:"notifyOnFail"`
OwnerId string `json:"ownerId"`
Slug string `json:"slug"`
State string `json:"state"`
UpdatedAt string `json:"updatedAt"`
}
type CursorService struct {
Cursor string `json:"cursor"`
Service Service `json:"service"`
}
// servicesCmd represents the services command
var servicesCmd = &cobra.Command{
Use: "services",
Short: "List services",
Long: `It's hackday!'`,
Run: func(cmd *cobra.Command, args []string) {
jsonString, err := http.Request("services")
if err != nil {
panic(err)
}
var cursorServices []CursorService
if err := json.Unmarshal(jsonString, &cursorServices); err != nil {
panic(err)
}
var services []Service
for _, cursorService := range cursorServices {
services = append(services, cursorService.Service)
}
if err := table.Print([]string{"Id", "Name", "Type", "State"}, services); err != nil {
panic(err)
}
},
}
func init() {
rootCmd.AddCommand(servicesCmd)
}