cmds/bootstrap: rm --all
Juan Batiz-Benet committed
Jan 5, 2015 at 07:59 UTC
730793e2f73db48c6098e16535df2e053dd59e7c
1 file changed
+28
-2
core/commands/bootstrap.go
+28
-2
@@ -100,7 +100,10 @@ var bootstrapRemoveCmd = &cmds.Command{
100
},
101
102
Arguments: []cmds.Argument{
103
- cmds.StringArg("peer", true, true, peerOptionDesc),
103
+ cmds.StringArg("peer", false, true, peerOptionDesc),
104
+ },
105
+ Options: []cmds.Option{
106
+ cmds.BoolOption("all", "Remove all bootstrap peers."),
107
},
108
Run: func(req cmds.Request) (interface{}, error) {
109
input, err := bootstrapInputToPeers(req.Arguments())
@@ -118,7 +121,17 @@ var bootstrapRemoveCmd = &cmds.Command{
121
return nil, err
122
}
123
121
- removed, err := bootstrapRemove(filename, cfg, input)
124
+ all, _, err := req.Option("all").Bool()
125
+ if err != nil {
126
+ return nil, err
127
+ }
128
+
129
+ var removed []*config.BootstrapPeer
130
+ if all {
131
+ removed, err = bootstrapRemoveAll(filename, cfg)
132
+ } else {
133
+ removed, err = bootstrapRemove(filename, cfg, input)
134
+ }
135
if err != nil {
136
return nil, err
137
}
@@ -276,6 +289,19 @@ func bootstrapRemove(filename string, cfg *config.Config, toRemove []*config.Boo
289
return removed, nil
290
}
291
292
+func bootstrapRemoveAll(filename string, cfg *config.Config) ([]*config.BootstrapPeer, error) {
293
+ removed := make([]*config.BootstrapPeer, len(cfg.Bootstrap))
294
+ copy(removed, cfg.Bootstrap)
295
+
296
+ cfg.Bootstrap = nil
297
+ err := config.WriteConfigFile(filename, cfg)
298
+ if err != nil {
299
+ return nil, err
300
+ }
301
+
302
+ return removed, nil
303
+}
304
+
305
const bootstrapSecurityWarning = `
306
SECURITY WARNING:
307