-
Notifications
You must be signed in to change notification settings - Fork 18
/
runstatus_service_delete.go
62 lines (49 loc) · 1.35 KB
/
runstatus_service_delete.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 runstatusServiceDeleteCmd = &cobra.Command{
Use: "delete [PAGE] SERVICE-NAME",
Short: "Delete a service",
Aliases: gDeleteAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
pageName := gCurrentAccount.DefaultRunstatusPage
serviceName := 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]
serviceName = args[1]
}
runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: pageName})
if err != nil {
return err
}
service, err := getServiceByName(*runstatusPage, serviceName)
if err != nil {
return err
}
// TODO: add "--force" flag
if !askQuestion(fmt.Sprintf("Are you sure you want to delete service %q?", serviceName)) {
return nil
}
if err := csRunstatus.DeleteRunstatusService(gContext, *service); err != nil {
return err
}
fmt.Printf("Service %q successfully deleted\n", serviceName)
return nil
},
}
func init() {
runstatusServiceCmd.AddCommand(runstatusServiceDeleteCmd)
}