提交 730793e2 作者: Juan Batiz-Benet

cmds/bootstrap: rm --all

上级 585e7164
...@@ -100,7 +100,10 @@ var bootstrapRemoveCmd = &cmds.Command{ ...@@ -100,7 +100,10 @@ var bootstrapRemoveCmd = &cmds.Command{
}, },
Arguments: []cmds.Argument{ Arguments: []cmds.Argument{
cmds.StringArg("peer", true, true, peerOptionDesc), cmds.StringArg("peer", false, true, peerOptionDesc),
},
Options: []cmds.Option{
cmds.BoolOption("all", "Remove all bootstrap peers."),
}, },
Run: func(req cmds.Request) (interface{}, error) { Run: func(req cmds.Request) (interface{}, error) {
input, err := bootstrapInputToPeers(req.Arguments()) input, err := bootstrapInputToPeers(req.Arguments())
...@@ -118,7 +121,17 @@ var bootstrapRemoveCmd = &cmds.Command{ ...@@ -118,7 +121,17 @@ var bootstrapRemoveCmd = &cmds.Command{
return nil, err return nil, err
} }
removed, err := bootstrapRemove(filename, cfg, input) all, _, err := req.Option("all").Bool()
if err != nil {
return nil, err
}
var removed []*config.BootstrapPeer
if all {
removed, err = bootstrapRemoveAll(filename, cfg)
} else {
removed, err = bootstrapRemove(filename, cfg, input)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -276,6 +289,19 @@ func bootstrapRemove(filename string, cfg *config.Config, toRemove []*config.Boo ...@@ -276,6 +289,19 @@ func bootstrapRemove(filename string, cfg *config.Config, toRemove []*config.Boo
return removed, nil return removed, nil
} }
func bootstrapRemoveAll(filename string, cfg *config.Config) ([]*config.BootstrapPeer, error) {
removed := make([]*config.BootstrapPeer, len(cfg.Bootstrap))
copy(removed, cfg.Bootstrap)
cfg.Bootstrap = nil
err := config.WriteConfigFile(filename, cfg)
if err != nil {
return nil, err
}
return removed, nil
}
const bootstrapSecurityWarning = ` const bootstrapSecurityWarning = `
SECURITY WARNING: SECURITY WARNING:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论