cmds/filestore: use PostRun in verify
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
Overbool committed
Nov 3, 2018 at 22:56 UTC
b4b6fc6906dd1279c1d09bef7383c7af3628194e
1 file changed
+22
-7
core/commands/filestore.go
+22
-7
@@ -7,6 +7,7 @@ import (
7
8
core "github.com/ipfs/go-ipfs/core"
9
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
10
+ e "github.com/ipfs/go-ipfs/core/commands/e"
11
filestore "github.com/ipfs/go-ipfs/filestore"
12
13
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
@@ -148,14 +149,28 @@ For ERROR entries the error will also be printed to stderr.
149
150
return nil
151
},
151
- Encoders: cmds.EncoderMap{
152
- cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *filestore.ListRes) error {
153
- if out.Status == filestore.StatusOtherError {
154
- fmt.Fprintf(os.Stderr, "%s\n", out.ErrorMsg)
152
+ PostRun: cmds.PostRunMap{
153
+ cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error {
154
+ for {
155
+ v, err := res.Next()
156
+ if err != nil {
157
+ if err == io.EOF {
158
+ return nil
159
+ }
160
+ return err
161
+ }
162
+
163
+ list, ok := v.(*filestore.ListRes)
164
+ if !ok {
165
+ return e.TypeErr(list, v)
166
+ }
167
+
168
+ if list.Status == filestore.StatusOtherError {
169
+ fmt.Fprintf(os.Stderr, "%s\n", list.ErrorMsg)
170
+ }
171
+ fmt.Fprintf(os.Stdout, "%s %s\n", list.Status.Format(), list.FormatLong())
172
}
156
- fmt.Fprintf(w, "%s %s\n", out.Status.Format(), out.FormatLong())
157
- return nil
158
- }),
173
+ },
174
},
175
Type: filestore.ListRes{},
176
}