-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.go
53 lines (43 loc) · 1.45 KB
/
start.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
package database
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"
)
// StartCommand creates the "database start" command
func StartCommand() commands.Command {
return &startCommand{
BaseCommand: commands.New(
"start",
"Start on a managed database",
"upctl database start b0952286-1193-4a81-a1af-62efc014ae4b",
"upctl database start b0952286-1193-4a81-a1af-62efc014ae4b 666bcd3c-5c63-428d-a4fd-07c27469a5a6",
"upctl database start pg-1x1xcpu-2gb-25gb-pl-waw1",
),
}
}
type startCommand struct {
*commands.BaseCommand
completion.Database
resolver.CachingDatabase
}
// Execute implements commands.MultipleArgumentCommand
func (s *startCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
svc := exec.All()
msg := fmt.Sprintf("Starting database %v", uuid)
logline := exec.NewLogEntry(msg)
logline.StartedNow()
logline.SetMessage(fmt.Sprintf("%s: sending request", msg))
res, err := svc.StartManagedDatabase(&request.StartManagedDatabaseRequest{
UUID: uuid,
})
if err != nil {
return commands.HandleError(logline, fmt.Sprintf("%s: failed", msg), err)
}
logline.SetMessage(fmt.Sprintf("%s: done", msg))
logline.MarkDone()
return output.OnlyMarshaled{Value: res}, nil
}