diff --git a/command/service_show.go b/command/service_show.go index d9af51a8..2534289d 100644 --- a/command/service_show.go +++ b/command/service_show.go @@ -1,11 +1,16 @@ package main import ( + "fmt" + "github.com/PagerDuty/go-pagerduty" + log "github.com/Sirupsen/logrus" "github.com/mitchellh/cli" + "gopkg.in/yaml.v2" "strings" ) type ServiceShow struct { + Meta } func ServiceShowCommand() (cli.Command, error) { @@ -14,7 +19,14 @@ func ServiceShowCommand() (cli.Command, error) { func (c *ServiceShow) Help() string { helpText := ` - ` + service show Show specific service + + Options: + + -id + -include + + ` + c.Meta.Help() return strings.TrimSpace(helpText) } @@ -23,5 +35,37 @@ func (c *ServiceShow) Synopsis() string { } func (c *ServiceShow) Run(args []string) int { + var includes []string + flags := c.Meta.FlagSet("service show") + flags.Usage = func() { fmt.Println(c.Help()) } + servID := flags.String("id", "", "Service ID") + flags.Var((*ArrayFlags)(&includes), "include", "Additional details to include (can be specified multiple times)") + if err := flags.Parse(args); err != nil { + log.Errorln(err) + return -1 + } + if err := c.Meta.Setup(); err != nil { + log.Error(err) + return -1 + } + if servID == nil { + log.Error("You must provide a service id") + return -1 + } + client := c.Meta.Client() + o := &pagerduty.GetServiceOptions{ + Includes: includes, + } + servicerecord, err := client.GetService(*servID, o) + if err != nil { + log.Error(err) + return -1 + } + data, err := yaml.Marshal(servicerecord) + if err != nil { + log.Error(err) + return -1 + } + fmt.Println(string(data)) return 0 } diff --git a/service.go b/service.go index 4525bfd3..a5b8f4aa 100644 --- a/service.go +++ b/service.go @@ -108,7 +108,7 @@ type GetServiceOptions struct { } // GetService gets details about an existing service. -func (c *Client) GetService(id string, o GetServiceOptions) (*Service, error) { +func (c *Client) GetService(id string, o *GetServiceOptions) (*Service, error) { v, err := query.Values(o) resp, err := c.get("/services/" + id + "?" + v.Encode()) return getServiceFromResponse(c, resp, err)