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

command: selectable output formats (JSON/YAML) #513

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ Example of config file:
authtoken: fooBar
```

#### Output formats

YAML and JSON output formats are supported. The default is YAML.

The key `outputformat` can be set in `.pd.yml`:

```yaml
authtoken: yourtokenhere
outputformat: json
```

Alternatively, the `--outputformat` command line flag can be used:

```
pd incident list --outputformat=json
```

#### Commands

`pd` command provides a single entrypoint for all the API endpoints, with individual
API represented by their own sub commands. For an exhaustive list of sub-commands, try:
```
Expand Down
2 changes: 1 addition & 1 deletion command/addon_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"strings"

"github.com/mitchellh/cli"
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
)

Expand Down
11 changes: 5 additions & 6 deletions command/addon_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"strings"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
log "github.com/sirupsen/logrus"
)

type AddonList struct {
Expand Down Expand Up @@ -62,9 +62,8 @@ func (c *AddonList) Run(args []string) int {
log.Error(err)
return -1
} else {
for i, addon := range addonList.Addons {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(addon)
for _, addon := range addonList.Addons {
data, err := c.Marshaler(addon)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/addon_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func (c *AddonShow) Run(args []string) int {
log.Error(err)
return -1
}
data, err := yaml.Marshal(a)
data, err := c.Marshaler(a)
if err != nil {
log.Error(err)
return -1
Expand Down
5 changes: 3 additions & 2 deletions command/addon_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"encoding/json"
"fmt"
"strings"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"strings"
log "github.com/sirupsen/logrus"
)

type AddonUpdate struct {
Expand Down
3 changes: 1 addition & 2 deletions command/analytics_incident_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -99,7 +98,7 @@ func (c *AnalyticsShow) Run(args []string) int {
return -1
}

aggregatedIncidentDataBytes, err := json.Marshal(aggregatedIncidentData)
aggregatedIncidentDataBytes, err := c.Marshaler(aggregatedIncidentData)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/analytics_service_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -97,7 +96,7 @@ func (c *AnalyticsServiceShow) Run(args []string) int {
return -1
}

aggregatedServiceDataBytes, err := json.Marshal(aggregatedServiceData)
aggregatedServiceDataBytes, err := c.Marshaler(aggregatedServiceData)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/analytics_team_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -97,7 +96,7 @@ func (c *AnalyticsTeamShow) Run(args []string) int {
return -1
}

aggregatedTeamDataBytes, err := json.Marshal(aggregatedTeamData)
aggregatedTeamDataBytes, err := c.Marshaler(aggregatedTeamData)
if err != nil {
log.Error(err)
return -1
Expand Down
7 changes: 4 additions & 3 deletions command/escalation_policy_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"os"
"strings"

"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
)

type EscalationPolicyCreate struct {
Expand Down
11 changes: 5 additions & 6 deletions command/escalation_policy_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"strings"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
log "github.com/sirupsen/logrus"
)

type EscalationPolicyList struct {
Expand Down Expand Up @@ -72,9 +72,8 @@ func (c *EscalationPolicyList) Run(args []string) int {
log.Error(err)
return -1
} else {
for i, p := range eps.EscalationPolicies {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(p)
for _, p := range eps.EscalationPolicies {
data, err := c.Marshaler(p)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/escalation_policy_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
)

Expand Down Expand Up @@ -62,7 +61,7 @@ func (c *EscalationPolicyShow) Run(args []string) int {
log.Error(err)
return -1
}
data, err := yaml.Marshal(ep)
data, err := c.Marshaler(ep)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/event_orchestration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type EventOrchestrationList struct {
Expand Down Expand Up @@ -62,7 +61,7 @@ func (c *EventOrchestrationList) Run(args []string) int {
if i > 0 {
fmt.Println("---")
}
data, err := yaml.Marshal(p)
data, err := c.Marshaler(p)
if err != nil {
log.Error(err)
return -1
Expand Down
5 changes: 2 additions & 3 deletions command/event_orchestration_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type EventOrchestrationShow struct {
Expand Down Expand Up @@ -59,7 +58,7 @@ func (c *EventOrchestrationShow) Run(args []string) int {
log.Error(err)
return -1
}
data, err := yaml.Marshal(ep)
data, err := c.Marshaler(ep)
if err != nil {
log.Error(err)
return -1
Expand All @@ -73,7 +72,7 @@ func (c *EventOrchestrationShow) Run(args []string) int {
log.Error(err)
return -1
}
data, err = yaml.Marshal(rules)
data, err = c.Marshaler(rules)
if err != nil {
log.Error(err)
return -1
Expand Down
2 changes: 1 addition & 1 deletion command/event_v2_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"

pagerduty "github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
)

type EventV2Manage struct {
Expand Down
11 changes: 5 additions & 6 deletions command/incident_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"strings"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
log "github.com/sirupsen/logrus"
)

type IncidentList struct {
Expand Down Expand Up @@ -60,9 +60,8 @@ func (c *IncidentList) Run(args []string) int {
log.Error(err)
return -1
} else {
for i, incident := range incidentList.Incidents {
fmt.Println("Entry: ", i+1)
data, err := yaml.Marshal(incident)
for _, incident := range incidentList.Incidents {
data, err := c.Marshaler(incident)
if err != nil {
log.Error(err)
return -1
Expand Down
7 changes: 4 additions & 3 deletions command/maintenance_window_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"os"
"strings"

"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
)

type MaintenanceWindowCreate struct {
Expand Down
6 changes: 2 additions & 4 deletions command/maintenance_window_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type MaintenanceWindowList struct {
Expand Down Expand Up @@ -73,9 +72,8 @@ func (c *MaintenanceWindowList) Run(args []string) int {
return -1
}

for i, mw := range mws.MaintenanceWindows {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(mw)
for _, mw := range mws.MaintenanceWindows {
data, err := c.Marshaler(mw)
if err != nil {
log.Error(err)
return -1
Expand Down
3 changes: 1 addition & 2 deletions command/maintenance_window_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/PagerDuty/go-pagerduty"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type MaintenanceWindowShow struct {
Expand Down Expand Up @@ -68,7 +67,7 @@ func (c *MaintenanceWindowShow) Run(args []string) int {
return -1
}

data, err := yaml.Marshal(mw)
data, err := c.Marshaler(mw)
if err != nil {
log.Error(err)
return -1
Expand Down
Loading