Skip to content

Commit

Permalink
Add service show functionality (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmluciano authored and ranjib committed Oct 18, 2016
1 parent 45ef516 commit bbe07a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion command/service_show.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bbe07a1

Please sign in to comment.