mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-21 00:47:22 +08:00
cmds/bootstrap: rm --all
This commit is contained in:
@ -100,7 +100,10 @@ var bootstrapRemoveCmd = &cmds.Command{
|
||||
},
|
||||
|
||||
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) {
|
||||
input, err := bootstrapInputToPeers(req.Arguments())
|
||||
@ -118,7 +121,17 @@ var bootstrapRemoveCmd = &cmds.Command{
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
@ -276,6 +289,19 @@ func bootstrapRemove(filename string, cfg *config.Config, toRemove []*config.Boo
|
||||
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 = `
|
||||
SECURITY WARNING:
|
||||
|
||||
|
Reference in New Issue
Block a user