cmds/bootstrap: fix marshalling + listing errors
Juan Batiz-Benet committed
Feb 1, 2015 at 05:36 UTC
188d336204c8e241096f1e9ab8e05b5954f84220
1 file changed
+16
-15
core/commands/bootstrap.go
+16
-15
@@ -14,7 +14,7 @@ import (
14
)
15
16
type BootstrapOutput struct {
17
- Peers []config.BootstrapPeer
17
+ Peers []string
18
}
19
20
var peerOptionDesc = "A peer to add to the bootstrap list (in the format '<multiaddr>/<peerID>')"
@@ -91,18 +91,18 @@ in the bootstrap list).
91
inputPeers = append(inputPeers, defltPeers...)
92
}
93
94
- added, err := bootstrapAdd(r, cfg, inputPeers)
95
- if err != nil {
96
- res.SetError(err, cmds.ErrNormal)
94
+ if len(inputPeers) == 0 {
95
+ res.SetError(errors.New("no bootstrap peers to add"), cmds.ErrClient)
96
return
97
}
98
100
- if len(inputPeers) == 0 {
101
- res.SetError(errors.New("no bootstrap peers to add"), cmds.ErrClient)
99
+ added, err := bootstrapAdd(r, cfg, inputPeers)
100
+ if err != nil {
101
+ res.SetError(err, cmds.ErrNormal)
102
return
103
}
104
105
- res.SetOutput(&BootstrapOutput{added})
105
+ res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(added)})
106
},
107
Type: BootstrapOutput{},
108
Marshalers: cmds.MarshalerMap{
@@ -168,7 +168,7 @@ var bootstrapRemoveCmd = &cmds.Command{
168
return
169
}
170
171
- res.SetOutput(&BootstrapOutput{removed})
171
+ res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(removed)})
172
},
173
Type: BootstrapOutput{},
174
Marshalers: cmds.MarshalerMap{
@@ -192,18 +192,20 @@ var bootstrapListCmd = &cmds.Command{
192
},
193
194
Run: func(req cmds.Request, res cmds.Response) {
195
- cfg, err := req.Context().GetConfig()
196
- if err != nil {
195
+ r := fsrepo.At(req.Context().ConfigRoot)
196
+ if err := r.Open(); err != nil {
197
res.SetError(err, cmds.ErrNormal)
198
return
199
}
200
+ defer r.Close()
201
+ cfg := r.Config()
202
203
peers, err := cfg.BootstrapPeers()
204
if err != nil {
205
res.SetError(err, cmds.ErrNormal)
206
return
207
}
206
- res.SetOutput(&BootstrapOutput{peers})
208
+ res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(peers)})
209
return
210
},
211
Type: BootstrapOutput{},
@@ -223,11 +225,10 @@ func bootstrapMarshaler(res cmds.Response) (io.Reader, error) {
225
return &buf, err
226
}
227
226
-func bootstrapWritePeers(w io.Writer, prefix string, peers []config.BootstrapPeer) error {
228
+func bootstrapWritePeers(w io.Writer, prefix string, peers []string) error {
229
228
- pstrs := config.BootstrapPeerStrings(peers)
229
- sort.Stable(sort.StringSlice(pstrs))
230
- for _, peer := range pstrs {
230
+ sort.Stable(sort.StringSlice(peers))
231
+ for _, peer := range peers {
232
_, err := w.Write([]byte(peer + "\n"))
233
if err != nil {
234
return err