/
stop.go
42 lines (34 loc) · 977 Bytes
/
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
package cmd
import (
"context"
"github.com/alexandrevilain/devpod-provider-ovhcloud/pkg/options"
"github.com/alexandrevilain/devpod-provider-ovhcloud/pkg/ovhcloud"
"github.com/loft-sh/devpod/pkg/log"
"github.com/spf13/cobra"
)
// StopCmd holds the "stop" command flags.
type StopCmd struct{}
// NewStopCmd creates the "stop" command.
func NewStopCmd() *cobra.Command {
cmd := &StopCmd{}
stopCmd := &cobra.Command{
Use: "stop",
Short: "Stop an instance",
RunE: func(_ *cobra.Command, args []string) error {
options, err := options.FromEnv(false)
if err != nil {
return err
}
return cmd.Run(context.Background(), options, log.Default)
},
}
return stopCmd
}
// Run runs "stop" the command logic.
func (cmd *StopCmd) Run(ctx context.Context, options *options.Options, log log.Logger) error {
client, err := ovhcloud.NewClient(options.Authentication)
if err != nil {
return err
}
return client.StopInstance(ctx, options.MachineID)
}