Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat)list service cli #5

Merged
merged 1 commit into from
Apr 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion command/addon_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func (c *AddonList) Help() string {

Options:

-query Filter escalation policies with certain name
-include Include additional details
-service-id Filter result by service ids
-filter Filter result by type
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}
Expand Down
2 changes: 1 addition & 1 deletion command/escalation_policy_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type EscalationPolicyShow struct {

func (c *EscalationPolicyShow) Help() string {
helpText := `
ep show show escalation policies
escalation-policy show Show escalation policies

Options:

Expand Down
55 changes: 55 additions & 0 deletions command/service_list.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 ServiceList struct {
Meta
}

func ServiceListCommand() (cli.Command, error) {
Expand All @@ -14,6 +19,13 @@ func ServiceListCommand() (cli.Command, error) {

func (c *ServiceList) Help() string {
helpText := `
pd service list List services

Options:
-include Include additional details
-team-id Filter result by team (can be specified multiple times)
-sort-by Sort result (name:asc, name:dsc)
-query Filter result by pattern (name or service key(
`
return strings.TrimSpace(helpText)
}
Expand All @@ -23,5 +35,48 @@ func (c *ServiceList) Synopsis() string {
}

func (c *ServiceList) Run(args []string) int {
var teamIDs []string
var timeZone string
var sortBy string
var query string
var includes []string
flags := c.Meta.FlagSet("service 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)(&teamIDs), "team-id", "Only show for team ID (can be specified multiple times)")
flags.StringVar(&timeZone, "time-zone", "", "Time Zone")
flags.StringVar(&sortBy, "sort-by", "", "sort by")
flags.StringVar(&query, "query", "", "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.ListServiceOptions{
TeamIDs: teamIDs,
TimeZone: timeZone,
SortBy: sortBy,
Query: query,
Includes: includes,
}
if serviceList, err := client.ListServices(opts); err != nil {
log.Error(err)
return -1
} else {
for i, service := range serviceList.Services {
fmt.Println("Entry: ", i+1)
data, err := yaml.Marshal(service)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
}
}
return 0
}
45 changes: 45 additions & 0 deletions examples/service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "Cha0tic App",
"description": "Some infinities are bigger than other infinities",
"auto_resolve_timeout": 14400,
"acknowledgement_timeout": 600,
"status": "active",
"escalation_policy": {
"id": "PWIP6CQ",
"type": "escalation_policy_reference"
},
"incident_urgency_rule": {
"type": "use_support_hours",
"during_support_hours": {
"type": "constant",
"urgency": "high"
},
"outside_support_hours": {
"type": "constant",
"urgency": "low"
}
},
"support_hours": {
"type": "fixed_time_per_day",
"time_zone": "Lima",
"start_time": "09:00:00",
"end_time": "17:00:00",
"days_of_week": [
1,
2,
3,
4,
5
]
},
"scheduled_actions": [
{
"type": "urgency_change",
"at": {
"type": "named_time",
"name": "support_hours_start"
},
"to_urgency": "high"
}
]
}