Commit c65b01c5 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

fix(add) cast safely

parent 084ffd97
......@@ -9,7 +9,7 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
"github.com/jbenet/go-ipfs/core"
core "github.com/jbenet/go-ipfs/core"
commands "github.com/jbenet/go-ipfs/core/commands2"
daemon "github.com/jbenet/go-ipfs/daemon2"
)
......
......@@ -62,14 +62,18 @@ var addCmd = &cmds.Command{
},
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
cmds.Text: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*AddOutput).Added
if len(v) == 1 {
s := fmt.Sprintf("Added object: %s\n", v[0].Hash)
val, ok := res.Output().(*AddOutput)
if !ok {
return nil, errors.New("cast err")
}
added := val.Added
if len(added) == 1 {
s := fmt.Sprintf("Added object: %s\n", added[0].Hash)
return []byte(s), nil
}
s := fmt.Sprintf("Added %v objects:\n", len(v))
for _, obj := range v {
s := fmt.Sprintf("Added %v objects:\n", len(added))
for _, obj := range added {
s += fmt.Sprintf("- %s\n", obj.Hash)
}
return []byte(s), nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment