1package main
2
3import (
4	"fmt"
5	"github.com/PagerDuty/go-pagerduty"
6	log "github.com/Sirupsen/logrus"
7	"github.com/mitchellh/cli"
8	"gopkg.in/yaml.v2"
9	"strings"
10)
11
12type EscalationPolicyShow struct {
13	Meta
14}
15
16func (c *EscalationPolicyShow) Help() string {
17	helpText := `
18	escalation-policy show  Show escalation policies
19
20	Options:
21
22		 -id
23		 -include
24
25	` + c.Meta.Help()
26	return strings.TrimSpace(helpText)
27}
28
29func (c *EscalationPolicyShow) Synopsis() string {
30	return "Show information about an existing escalation policy and its rules"
31}
32
33func EscalationPolicyShowCommand() (cli.Command, error) {
34	return &EscalationPolicyShow{}, nil
35}
36
37func (c *EscalationPolicyShow) Run(args []string) int {
38	var includes []string
39	var epID string
40	flags := c.Meta.FlagSet("ep show")
41	flags.Usage = func() { fmt.Println(c.Help()) }
42	flags.StringVar(&epID, "id", "", "Escalation policy id")
43	flags.Var((*ArrayFlags)(&includes), "include", "Additional details to include (can be specified multiple times)")
44	if err := flags.Parse(args); err != nil {
45		log.Errorln(err)
46		return -1
47	}
48	if err := c.Meta.Setup(); err != nil {
49		log.Error(err)
50		return -1
51	}
52	if epID == "" {
53		log.Error("You must provide escalation policy id")
54		return -1
55	}
56	client := c.Meta.Client()
57	o := &pagerduty.GetEscalationPolicyOptions{
58		Includes: includes,
59	}
60	ep, err := client.GetEscalationPolicy(epID, o)
61	if err != nil {
62		log.Error(err)
63		return -1
64	}
65	data, err := yaml.Marshal(ep)
66	if err != nil {
67		log.Error(err)
68		return -1
69	}
70	fmt.Println(string(data))
71	return 0
72}
73