-
Notifications
You must be signed in to change notification settings - Fork 244
/
vendor_list.go
70 lines (57 loc) · 1.29 KB
/
vendor_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
package main
import (
"fmt"
"strings"
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
type VendorList struct {
Meta
}
func VendorListCommand() (cli.Command, error) {
return &VendorList{}, nil
}
func (c *VendorList) Help() string {
helpText := `
pd vendor list List vendors
Options:
-query Filter vendors with certain name
`
return strings.TrimSpace(helpText)
}
func (c *VendorList) Synopsis() string {
return "List vendors within PagerDuty, optionally filtered by a search query"
}
func (c *VendorList) Run(args []string) int {
var query string
flags := c.Meta.FlagSet("user list")
flags.Usage = func() { fmt.Println(c.Help()) }
flags.StringVar(&query, "query", "", "Show vendors whose names contain the query")
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.ListVendorOptions{}
if resp, err := client.ListVendors(opts); err != nil {
log.Error(err)
return -1
} else {
for i, p := range resp.Vendors {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(p)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
}
}
return 0
}