-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_delete.go
117 lines (96 loc) · 1.99 KB
/
cmd_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"github.com/grimdork/foreman/api"
"github.com/grimdork/opt"
)
// CmdDeleteCanary options.
type CmdDeleteCanary struct {
opt.DefaultHelp
Name string `placeholder:"NAME" help:"Name of the canary to delete."`
Force bool `short:"f" help:"Force deletion of the canary."`
}
// Run the set command.
func (cmd *CmdDeleteCanary) Run(in []string) error {
if cmd.Help || cmd.Name == "" {
return opt.ErrUsage
}
cfg, err := loadConfig()
if err != nil {
return err
}
if !cmd.Force {
if !confirm() {
return nil
}
}
req := map[string]string{
"name": cmd.Name,
}
_, err = cfg.Delete(api.EPCanary, req)
if err != nil {
return err
}
fmt.Printf("Deleted canary %s\n", cmd.Name)
return nil
}
// CmdDeleteScout options.
type CmdDeleteScout struct {
opt.DefaultHelp
Hostname string `placeholder:"HOSTNAME" help:"Hostname of the scout to delete."`
Force bool `short:"f" help:"Force deletion of the scout."`
}
// Run the set command.
func (cmd *CmdDeleteScout) Run(in []string) error {
if cmd.Help || cmd.Hostname == "" {
return opt.ErrUsage
}
cfg, err := loadConfig()
if err != nil {
return err
}
if !cmd.Force {
if !confirm() {
return nil
}
}
req := map[string]string{
"hostname": cmd.Hostname,
}
_, err = cfg.Delete(api.EPScout, req)
if err != nil {
return err
}
fmt.Printf("Deleted scout %s\n", cmd.Hostname)
return nil
}
// CmdDeleteKey options.
type CmdDeleteKey struct {
opt.DefaultHelp
ID string `placeholder:"ID" help:"ID of the key to delete."`
Force bool `short:"f" help:"Force deletion of the key."`
}
// Run the set command.
func (cmd *CmdDeleteKey) Run(in []string) error {
if cmd.Help || cmd.ID == "" {
return opt.ErrUsage
}
cfg, err := loadConfig()
if err != nil {
return err
}
if !cmd.Force {
if !confirm() {
return nil
}
}
req := map[string]string{
"keyid": cmd.ID,
}
_, err = cfg.Delete(api.EPKey, req)
if err != nil {
return err
}
fmt.Printf("Deleted key %s\n", cmd.ID)
return nil
}