forked from hetznercloud/cli
/
server_disable_rescue.go
43 lines (36 loc) · 1 KB
/
server_disable_rescue.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
package cli
import (
"fmt"
"github.com/spf13/cobra"
)
func newServerDisableRescueCommand(cli *CLI) *cobra.Command {
cmd := &cobra.Command{
Use: "disable-rescue [FLAGS] SERVER",
Short: "Disable rescue for a server",
Args: cobra.ExactArgs(1),
TraverseChildren: true,
DisableFlagsInUseLine: true,
PreRunE: cli.ensureToken,
RunE: cli.wrap(runServerDisableRescue),
}
return cmd
}
func runServerDisableRescue(cli *CLI, cmd *cobra.Command, args []string) error {
idOrName := args[0]
server, _, err := cli.Client().Server.Get(cli.Context, idOrName)
if err != nil {
return err
}
if server == nil {
return fmt.Errorf("server not found: %s", idOrName)
}
action, _, err := cli.Client().Server.DisableRescue(cli.Context, server)
if err != nil {
return err
}
if err := cli.ActionProgress(cli.Context, action); err != nil {
return err
}
fmt.Printf("Rescue disabled for server %s\n", server.Name)
return nil
}