-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_incident_show.go
60 lines (48 loc) · 1.53 KB
/
runstatus_incident_show.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
package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// runstatusIncidentShowCmd represents the show command
var runstatusIncidentShowCmd = &cobra.Command{
Use: "show [page name] <incident name | id>",
Short: "Show an incident detail",
Aliases: gShowAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
pageName := gCurrentAccount.DefaultRunstatusPage
incidentName := args[0]
if gCurrentAccount.DefaultRunstatusPage == "" && len(args) == 1 {
fmt.Fprintf(os.Stderr, `Error: No default runstat.us page is set:
Please specify a page in parameter or add it to %q
`, gConfigFilePath)
return cmd.Usage()
}
if len(args) > 1 {
pageName = args[0]
incidentName = args[1]
}
runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: pageName})
if err != nil {
return err
}
incident, err := getIncidentByNameOrID(*runstatusPage, incidentName)
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
fmt.Fprintf(w, "Title:\t%s\n", incident.Title) // nolint: errcheck
fmt.Fprintf(w, "Description:\t%s\n", incident.StatusText) // nolint: errcheck
fmt.Fprintf(w, "State:\t%s\n", incident.State) // nolint: errcheck
fmt.Fprintf(w, "Status:\t%s\n", incident.Status) // nolint: errcheck
return w.Flush()
},
}
func init() {
runstatusIncidentCmd.AddCommand(runstatusIncidentShowCmd)
}