-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_incident_remove.go
63 lines (50 loc) · 1.48 KB
/
runstatus_incident_remove.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
package cmd
import (
"fmt"
"os"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// removeCmd represents the remove command
var runstatusIncidentRemoveCmd = &cobra.Command{
Use: "remove [page name] <incident name | id>",
Short: "Remove incident from a runstat.us page",
Aliases: gRemoveAlias,
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
}
// TODO: add "--force" flag
if !askQuestion(fmt.Sprintf("sure you want to delete %q incident", incidentName)) {
return nil
}
if err := csRunstatus.DeleteRunstatusIncident(gContext, *incident); err != nil {
return fmt.Errorf("error removing %q:\n%v", incidentName, err)
}
fmt.Printf("Incident %q successfully removed\n", incidentName)
return nil
},
}
func init() {
runstatusIncidentCmd.AddCommand(runstatusIncidentRemoveCmd)
}