-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
remove_domains.go
46 lines (39 loc) · 1017 Bytes
/
remove_domains.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
package cmd
import (
"github.com/spf13/cobra"
"github.com/guumaster/hostctl/pkg/host"
)
// removeDomainsCmd represents the remove command
var removeDomainsCmd = &cobra.Command{
Use: "domains",
Short: "Remove domains from your hosts file.",
Long: `
Completely remove domains from your hosts file.
It cannot be undone unless you have a backup and restore it.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
profile, _ := cmd.Flags().GetString("profile")
if 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.RemoveDomains(dst, profile, args)
if err != nil {
return err
}
if quiet {
return nil
}
return host.ListProfiles(dst, &host.ListOptions{
Profile: profile,
})
},
}