-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
disable.go
59 lines (49 loc) · 1.22 KB
/
disable.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
package cmd
import (
"github.com/spf13/cobra"
"github.com/guumaster/hostctl/pkg/host"
)
// disableCmd represents the disable command
var disableCmd = &cobra.Command{
Use: "disable",
Short: "Disable a profile from your hosts file.",
Long: `
Disable a profile from your hosts file without removing it.
It will be listed as "off" while it is disabled.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
profile, _ := cmd.Flags().GetString("profile")
all, _ := cmd.Flags().GetBool("all")
if !all && profile == "" {
return host.MissingProfileError
}
if profile == "default" {
return host.DefaultProfileError
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
src, _ := cmd.Flags().GetString("host-file")
profile, _ := cmd.Flags().GetString("profile")
quiet, _ := cmd.Flags().GetBool("quiet")
all, _ := cmd.Flags().GetBool("all")
var err error
if all {
profile = ""
}
err = host.Disable(src, profile)
if err != nil {
return err
}
if quiet {
return nil
}
return host.ListProfiles(src, &host.ListOptions{
Profile: profile,
})
},
}
func init() {
rootCmd.AddCommand(disableCmd)
disableCmd.Flags().BoolP("all", "", false, "Disable all profiles")
}