/
start.go
57 lines (46 loc) · 1.48 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
54
55
56
57
package server
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 "server start" command
func StartCommand() commands.Command {
return &startCommand{
BaseCommand: commands.New(
"start",
"Start a server",
"upctl server start 00038afc-d526-4148-af0e-d2f1eeaded9b",
"upctl server start 00038afc-d526-4148-af0e-d2f1eeaded9b 0053a6f5-e6d1-4b0b-b9dc-b90d0894e8d0",
"upctl server start my_server1",
),
}
}
type startCommand struct {
*commands.BaseCommand
completion.Server
resolver.CachingServer
}
// InitCommand implements Command.InitCommand
func (s *startCommand) InitCommand() {
}
// Execute implements commands.MultipleArgumentCommand
func (s *startCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
svc := exec.Server()
msg := fmt.Sprintf("Starting server %v", uuid)
logline := exec.NewLogEntry(msg)
logline.StartedNow()
logline.SetMessage(fmt.Sprintf("%s: sending request", msg))
res, err := svc.StartServer(&request.StartServerRequest{
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
}