Browse Source

add subcommand to remove entire section

master
Chris Wiegman 9 months ago
parent
commit
7e131b2d18
Signed by: chriswiegman <chris@chriswiegman.com> GPG Key ID: 2B23D7A74FDE2DF4
1 changed files with 26 additions and 1 deletions
  1. +26
    -1
      cmd/main.go

+ 26
- 1
cmd/main.go View File

@ -22,6 +22,7 @@ Usage:
goodhosts add <ip> <host>...
goodhosts (rm|remove) <ip> <host>...
goodhosts list [--all]
goodhosts removesection <section>
goodhosts -h | --help
goodhosts --version
@ -30,7 +31,7 @@ Options:
-h --help Show this screen.
--version Show the version.`
args, _ := docopt.Parse(usage, nil, true, "Goodhosts 3.1.1", false)
args, _ := docopt.Parse(usage, nil, true, "Goodhosts 3.2.0", false)
hosts, err := goodhosts.NewHosts("")
check(err)
@ -119,4 +120,28 @@ Options:
return
}
if args["removesection"].(bool) {
section := args["<section>"].(string)
hosts, err := goodhosts.NewHosts(section)
check(err)
if !hosts.IsWritable() {
fmt.Fprintln(os.Stderr, "Host file not writable. Try running with elevated privileges.")
os.Exit(1)
}
err = hosts.RemoveSection()
if err != nil {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", err.Error()))
os.Exit(2)
}
err = hosts.Flush()
check(err)
return
}
}

Loading…
Cancel
Save