-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
remove.go
60 lines (47 loc) · 1.27 KB
/
remove.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"
"github.com/spf13/cobra"
"github.com/guumaster/hostctl/pkg/host"
)
// removeCmd represents the remove command
var removeCmd = &cobra.Command{
Use: "remove",
Short: "Remove a profile from your hosts file.",
Long: `
Completely remove a profile content from your hosts file.
It cannot be undone unless you have a backup and restore it.
If you want to remove a profile but would like to use it later,
use 'hosts disable' instead.
`,
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 {
profile, _ := cmd.Flags().GetString("profile")
dst, _ := cmd.Flags().GetString("host-file")
quiet, _ := cmd.Flags().GetBool("quiet")
err := host.RemoveProfile(dst, profile)
if err != nil {
return err
}
if quiet {
return nil
}
fmt.Printf("Profile '%s' removed.\n\n", profile)
return nil
},
}
func init() {
rootCmd.AddCommand(removeCmd)
removeCmd.Flags().Bool("all", false, "Remove all profiles")
removeCmd.AddCommand(removeDomainsCmd)
}