Skip to content

Commit

Permalink
cmds/filestore: use PostRun in verify
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
  • Loading branch information
overbool committed Nov 6, 2018
1 parent f085d13 commit 55572fe
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions core/commands/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

core "github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
filestore "github.com/ipfs/go-ipfs/filestore"

cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
Expand Down Expand Up @@ -148,14 +149,28 @@ For ERROR entries the error will also be printed to stderr.

return nil
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *filestore.ListRes) error {
if out.Status == filestore.StatusOtherError {
fmt.Fprintf(os.Stderr, "%s\n", out.ErrorMsg)
PostRun: cmds.PostRunMap{
cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error {
for {
v, err := res.Next()
if err != nil {
if err == io.EOF {
return nil
}
return err
}

list, ok := v.(*filestore.ListRes)
if !ok {
return e.TypeErr(list, v)
}

if list.Status == filestore.StatusOtherError {
fmt.Fprintf(os.Stderr, "%s\n", list.ErrorMsg)
}
fmt.Fprintf(os.Stdout, "%s %s\n", list.Status.Format(), list.FormatLong())
}
fmt.Fprintf(w, "%s %s\n", out.Status.Format(), out.FormatLong())
return nil
}),
},
},
Type: filestore.ListRes{},
}
Expand Down

0 comments on commit 55572fe

Please sign in to comment.