-
Notifications
You must be signed in to change notification settings - Fork 20
/
instance_start.go
60 lines (44 loc) · 1.42 KB
/
instance_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
package cmd
import (
"fmt"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type instanceStartCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"start"`
Instance string `cli-arg:"#" cli-usage:"NAME|ID"`
Force bool `cli-short:"f" cli-usage:"don't prompt for confirmation"`
Zone string `cli-short:"z" cli-usage:"instance zone"`
}
func (c *instanceStartCmd) cmdAliases() []string { return nil }
func (c *instanceStartCmd) cmdShort() string { return "Start a Compute instance" }
func (c *instanceStartCmd) cmdLong() string { return "" }
func (c *instanceStartCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *instanceStartCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, c.Zone))
instance, err := cs.FindInstance(ctx, c.Zone, c.Instance)
if err != nil {
return err
}
if !c.Force {
if !askQuestion(fmt.Sprintf("Are you sure you want to start instance %q?", c.Instance)) {
return nil
}
}
decorateAsyncOperation(fmt.Sprintf("Starting instance %q...", c.Instance), func() {
err = instance.Start(ctx)
})
if err != nil {
return err
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(computeInstanceCmd, &instanceStartCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}