-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete.go
55 lines (45 loc) · 1.42 KB
/
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
package router
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/internal/output"
"github.com/UpCloudLtd/upcloud-cli/internal/resolver"
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
)
type deleteCommand struct {
*commands.BaseCommand
resolver.CachingRouter
completion.Router
}
// DeleteCommand creates the "delete router" command
func DeleteCommand() commands.Command {
return &deleteCommand{
BaseCommand: commands.New(
"delete",
"Delete a router",
"upctl router delete 0497728e-76ef-41d0-997f-fa9449eb71bc",
"upctl router delete my_router",
),
}
}
// InitCommand implements Command.InitCommand
func (s *deleteCommand) InitCommand() {
}
// MaximumExecutions implements Command.MaximumExecutions
func (s *deleteCommand) MaximumExecutions() int {
return maxRouterActions
}
// Execute implements commands.MultipleArgumentCommand
func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) {
msg := fmt.Sprintf("Deleting router %s", arg)
logline := exec.NewLogEntry(msg)
logline.StartedNow()
err := exec.Network().DeleteRouter(&request.DeleteRouterRequest{UUID: arg})
if err != nil {
return commands.HandleError(logline, fmt.Sprintf("%s: failed", msg), err)
}
logline.SetMessage(fmt.Sprintf("%s: done", msg))
logline.MarkDone()
return output.None{}, nil
}