浏览代码

add subcommand to remove entire section

tags/v3.2.0
Chris Wiegman 7 个月前
父节点
当前提交
7e131b2d18
签署人:: chriswiegman <chris@chriswiegman.com> GPG 密钥 ID: 2B23D7A74FDE2DF4
共有 1 个文件被更改,包括 26 次插入1 次删除
  1. +26
    -1
      cmd/main.go

+ 26
- 1
cmd/main.go 查看文件

@@ -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
}
}

正在加载...
取消
保存