-
Notifications
You must be signed in to change notification settings - Fork 6
/
delete.go
48 lines (39 loc) · 1.28 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 database
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"
)
type deleteCommand struct {
*commands.BaseCommand
resolver.CachingDatabase
completion.Database
}
// DeleteCommand creates the "delete database" command
func DeleteCommand() commands.Command {
return &deleteCommand{
BaseCommand: commands.New(
"delete",
"Delete a database",
"upctl database delete 0497728e-76ef-41d0-997f-fa9449eb71bc",
"upctl database delete my_database",
),
}
}
// InitCommand implements Command.InitCommand
func (s *deleteCommand) InitCommand() {
}
// Execute implements commands.MultipleArgumentCommand
func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) {
msg := fmt.Sprintf("Deleting database %s", arg)
exec.PushProgressStarted(msg)
err := exec.All().DeleteManagedDatabase(exec.Context(), &request.DeleteManagedDatabaseRequest{UUID: arg})
if err != nil {
return commands.HandleError(exec, fmt.Sprintf("%s: failed", msg), err)
}
exec.PushProgressSuccess(msg)
return output.None{}, nil
}