-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.go
64 lines (52 loc) · 1.61 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
58
59
60
61
62
63
64
package server
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/spf13/pflag"
"github.com/UpCloudLtd/upcloud-go-api/v8/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
host int
avoidHost int
}
// InitCommand implements Command.InitCommand
func (s *startCommand) InitCommand() {
fs := &pflag.FlagSet{}
fs.IntVar(&s.avoidHost, "avoid-host", 0, avoidHostDescription)
fs.IntVar(&s.host, "host", 0, hostDescription)
s.AddFlags(fs)
}
// 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)
exec.PushProgressStarted(msg)
res, err := svc.StartServer(exec.Context(), &request.StartServerRequest{
UUID: uuid,
AvoidHost: s.avoidHost,
Host: s.host,
})
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.OnlyMarshaled{Value: res}, nil
}