-
Notifications
You must be signed in to change notification settings - Fork 18
/
runstatus_incident_list.go
78 lines (63 loc) · 1.86 KB
/
runstatus_incident_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cmd
import (
"fmt"
"strings"
"time"
"github.com/spf13/cobra"
)
type runstatusIncidentListItemOutput struct {
ID int `json:"id"`
Page string `json:"page"`
Title string `json:"title"`
StartDate *time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"`
State string `json:"state"`
Status string `json:"status"`
}
type runstatusIncidentListOutput []runstatusIncidentListItemOutput
func (o *runstatusIncidentListOutput) toJSON() { outputJSON(o) }
func (o *runstatusIncidentListOutput) toText() { outputText(o) }
func (o *runstatusIncidentListOutput) toTable() {
for i := range *o {
(*o)[i].State = strings.ToUpper(strings.Replace((*o)[i].State, "_", " ", -1))
}
outputTable(o)
}
func init() {
runstatusIncidentCmd.AddCommand(&cobra.Command{
Use: "list [PAGE]...",
Short: "List incidents",
Long: fmt.Sprintf(`This command lists existing runstat.us incidents.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&runstatusIncidentListOutput{}), ", ")),
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
return output(runstatusListIncidents(args))
},
})
}
func runstatusListIncidents(pageNames []string) (outputter, error) {
pages, err := getRunstatusPages(pageNames)
if err != nil {
return nil, err
}
out := runstatusIncidentListOutput{}
for _, page := range pages {
incidents, err := csRunstatus.ListRunstatusIncidents(gContext, page)
if err != nil {
return nil, err
}
for _, incident := range incidents {
out = append(out, runstatusIncidentListItemOutput{
ID: incident.ID,
Title: incident.Title,
StartDate: incident.StartDate,
EndDate: incident.EndDate,
State: incident.State,
Status: incident.Status,
Page: page.Subdomain,
})
}
}
return &out, nil
}