-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete.go
48 lines (39 loc) · 1.21 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
package servergroup
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
)
// DeleteCommand creates the "servergroup delete" command
func DeleteCommand() commands.Command {
return &deleteCommand{
BaseCommand: commands.New(
"delete",
"Delete a server group",
"upctl servergroup delete 8abc8009-4325-4b23-4321-b1232cd81231",
"upctl servergroup delete my-server-group",
),
}
}
type deleteCommand struct {
*commands.BaseCommand
resolver.CachingServerGroup
completion.ServerGroup
}
// Execute implements commands.MultipleArgumentCommand
func (c *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) {
svc := exec.All()
msg := fmt.Sprintf("Deleting server group %v", arg)
exec.PushProgressStarted(msg)
err := svc.DeleteServerGroup(exec.Context(), &request.DeleteServerGroupRequest{
UUID: arg,
})
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.None{}, nil
}