/
disable_protection.go
44 lines (38 loc) · 1.11 KB
/
disable_protection.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
package server
import (
"fmt"
"github.com/spf13/cobra"
"github.com/hetznercloud/cli/internal/cmd/base"
"github.com/hetznercloud/cli/internal/cmd/cmpl"
"github.com/hetznercloud/cli/internal/hcapi2"
"github.com/hetznercloud/cli/internal/state"
)
var DisableProtectionCmd = base.Cmd{
BaseCobraCommand: func(client hcapi2.Client) *cobra.Command {
return &cobra.Command{
Use: "disable-protection <server> <protection-level>...",
Short: "Disable resource protection for a server",
ValidArgsFunction: cmpl.SuggestArgs(
cmpl.SuggestCandidatesF(client.Server().Names),
cmpl.SuggestCandidates("delete", "rebuild"),
),
TraverseChildren: true,
DisableFlagsInUseLine: true,
}
},
Run: func(s state.State, cmd *cobra.Command, args []string) error {
idOrName := args[0]
server, _, err := s.Client().Server().Get(s, idOrName)
if err != nil {
return err
}
if server == nil {
return fmt.Errorf("server not found: %s", idOrName)
}
opts, err := getChangeProtectionOpts(false, args[1:])
if err != nil {
return err
}
return changeProtection(s, cmd, server, false, opts)
},
}