-
Notifications
You must be signed in to change notification settings - Fork 18
/
runstatus_maintenance_remove.go
62 lines (50 loc) · 1.51 KB
/
runstatus_maintenance_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
package cmd
import (
"fmt"
"os"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
var runstatusMaintenanceRemoveCmd = &cobra.Command{
Use: "remove [PAGE] MAINTENANCE-NAME",
Short: "Remove maintenance 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
maintenanceName := args[0]
if gCurrentAccount.DefaultRunstatusPage == "" && len(args) == 1 {
fmt.Fprintf(os.Stderr, `Missing page argument.
Please specify a page in parameter or
Set the key "defaultRunstatusPage" into %q.
`, gConfigFilePath)
return fmt.Errorf("missing default runstat.us page")
}
if len(args) > 1 {
pageName = args[0]
maintenanceName = args[1]
}
runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: pageName})
if err != nil {
return err
}
maintenance, err := getRunstatusMaintenanceByNameOrID(*runstatusPage, maintenanceName)
if err != nil {
return err
}
// TODO: add "--force" flag
if !askQuestion(fmt.Sprintf("Remove maintenance %q (%d) from %q?", maintenance.Title, maintenance.ID, pageName)) {
return nil
}
if err := csRunstatus.DeleteRunstatusMaintenance(gContext, *maintenance); err != nil {
return fmt.Errorf("error removing %q:\n%v", maintenanceName, err)
}
fmt.Println(maintenance.ID)
return nil
},
}
func init() {
runstatusMaintenanceCmd.AddCommand(runstatusMaintenanceRemoveCmd)
}