diff --git a/core/commands/id.go b/core/commands/id.go index fdc025560..f08af7d95 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -10,7 +10,6 @@ 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" ic "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto" "gx/ipfs/QmTRhk7cgjUf2gfQ3p2M9KPECNZEW9XUrmHcFCgog4cPgB/go-libp2p-peer" @@ -112,25 +111,20 @@ EXAMPLE: return cmds.EmitOnce(res, output) }, Encoders: cmds.EncoderMap{ - cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error { - val, ok := v.(*IdOutput) - if !ok { - return e.TypeErr(val, v) - } - + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *IdOutput) error { format, found := req.Options[formatOptionName].(string) if found { output := format - output = strings.Replace(output, "", val.ID, -1) - output = strings.Replace(output, "", val.AgentVersion, -1) - output = strings.Replace(output, "", val.ProtocolVersion, -1) - output = strings.Replace(output, "", val.PublicKey, -1) - output = strings.Replace(output, "", strings.Join(val.Addresses, "\n"), -1) + output = strings.Replace(output, "", out.ID, -1) + output = strings.Replace(output, "", out.AgentVersion, -1) + output = strings.Replace(output, "", out.ProtocolVersion, -1) + output = strings.Replace(output, "", out.PublicKey, -1) + output = strings.Replace(output, "", strings.Join(out.Addresses, "\n"), -1) output = strings.Replace(output, "\\n", "\n", -1) output = strings.Replace(output, "\\t", "\t", -1) fmt.Fprint(w, output) } else { - marshaled, err := json.MarshalIndent(val, "", "\t") + marshaled, err := json.MarshalIndent(out, "", "\t") if err != nil { return err }