-
Notifications
You must be signed in to change notification settings - Fork 244
/
addon_list.go
76 lines (67 loc) · 1.75 KB
/
addon_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
)
type AddonList struct {
Meta
}
func (c *AddonList) Help() string {
helpText := `
pd addon list List all of the existing escalation policies
Options:
-include Include additional details
-service-id Filter result by service ids
-filter Filter result by type
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}
func (c *AddonList) Synopsis() string {
return "List all addons"
}
func AddonListCommand() (cli.Command, error) {
return &AddonList{}, nil
}
func (c *AddonList) Run(args []string) int {
var includes []string
var serviceIDs []string
var filter string
flags := c.Meta.FlagSet("addon list")
flags.Usage = func() { fmt.Println(c.Help()) }
flags.Var((*ArrayFlags)(&includes), "include", "Additional details to include (can be specified multiple times)")
flags.Var((*ArrayFlags)(&serviceIDs), "service-id", "Show addons only for specified services (can be specified multiple times)")
flags.StringVar(&filter, "filter", "", "Filter results, showing only add-ons of the given type")
if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
client := c.Meta.Client()
opts := pagerduty.ListAddonOptions{
Includes: includes,
ServiceIDs: serviceIDs,
Filter: filter,
}
if addonList, err := client.ListAddons(opts); err != nil {
log.Error(err)
return -1
} else {
for i, addon := range addonList.Addons {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(addon)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
}
}
return 0
}