Fix refs local marshalling
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jun 6, 2016 at 12:31 UTC
953448af829f9fe5bd00099a1d6bf05d0d0c3928
1 file changed
+36
-37
core/commands/refs.go
+36
-37
@@ -117,35 +117,8 @@ NOTE: List all references recursively by using the flag '-r'.
117
}
118
}()
119
},
120
- Marshalers: cmds.MarshalerMap{
121
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
122
- outChan, ok := res.Output().(<-chan interface{})
123
- if !ok {
124
- return nil, u.ErrCast()
125
- }
126
-
127
- marshal := func(v interface{}) (io.Reader, error) {
128
- obj, ok := v.(*RefWrapper)
129
- if !ok {
130
- fmt.Println("%#v", v)
131
- return nil, u.ErrCast()
132
- }
133
-
134
- if obj.Err != "" {
135
- return nil, errors.New(obj.Err)
136
- }
137
-
138
- return strings.NewReader(obj.Ref + "\n"), nil
139
- }
140
-
141
- return &cmds.ChannelMarshaler{
142
- Channel: outChan,
143
- Marshaler: marshal,
144
- Res: res,
145
- }, nil
146
- },
147
- },
148
- Type: RefWrapper{},
120
+ Marshalers: refsMarshallerMap,
121
+ Type: RefWrapper{},
122
}
123
124
var RefsLocalCmd = &cmds.Command{
@@ -171,21 +144,47 @@ Displays the hashes of all local objects.
144
return
145
}
146
174
- piper, pipew := io.Pipe()
147
+ out := make(chan interface{})
148
+ res.SetOutput((<-chan interface{})(out))
149
150
go func() {
177
- defer pipew.Close()
151
+ defer close(out)
152
153
for k := range allKeys {
180
- s := k.B58String() + "\n"
181
- if _, err := pipew.Write([]byte(s)); err != nil {
182
- log.Error("pipe write error: ", err)
183
- return
184
- }
154
+ out <- &RefWrapper{Ref: k.B58String()}
155
}
156
}()
157
+ },
158
+ Marshalers: refsMarshallerMap,
159
+ Type: RefWrapper{},
160
+}
161
+
162
+var refsMarshallerMap = cmds.MarshalerMap{
163
+ cmds.Text: func(res cmds.Response) (io.Reader, error) {
164
+ outChan, ok := res.Output().(<-chan interface{})
165
+ if !ok {
166
+ return nil, u.ErrCast()
167
+ }
168
+
169
+ marshal := func(v interface{}) (io.Reader, error) {
170
+ obj, ok := v.(*RefWrapper)
171
+ if !ok {
172
+ fmt.Println("%#v", v)
173
+ return nil, u.ErrCast()
174
+ }
175
+
176
+ if obj.Err != "" {
177
+ return nil, errors.New(obj.Err)
178
+ }
179
+
180
+ return strings.NewReader(obj.Ref + "\n"), nil
181
+ }
182
188
- res.SetOutput(piper)
183
+ return &cmds.ChannelMarshaler{
184
+ Channel: outChan,
185
+ Marshaler: marshal,
186
+ Res: res,
187
+ }, nil
188
},
189
}
190