-
Notifications
You must be signed in to change notification settings - Fork 6
/
stop.go
55 lines (44 loc) · 1.44 KB
/
stop.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 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"
)
// StopCommand creates the "database stop" command
func StopCommand() commands.Command {
return &stopCommand{
BaseCommand: commands.New(
"stop",
"Stop a managed database",
"upctl database stop b0952286-1193-4a81-a1af-62efc014ae4b",
"upctl database stop b0952286-1193-4a81-a1af-62efc014ae4b 666bcd3c-5c63-428d-a4fd-07c27469a5a6",
"upctl database stop pg-1x1xcpu-2gb-25gb-pl-waw1",
),
}
}
type stopCommand struct {
*commands.BaseCommand
completion.Database
resolver.CachingDatabase
}
// InitCommand implements Command.InitCommand
func (s *stopCommand) InitCommand() {
s.Cobra().Aliases = []string{"shutdown"}
}
// Execute implements commands.MultipleArgumentCommand
func (s *stopCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
svc := exec.All()
msg := fmt.Sprintf("Stopping database %v", uuid)
exec.PushProgressStarted(msg)
res, err := svc.ShutdownManagedDatabase(exec.Context(), &request.ShutdownManagedDatabaseRequest{
UUID: uuid,
})
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.OnlyMarshaled{Value: res}, nil
}