From b3da13a4afb97c97f0acb1bea7954260b20e7721 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Fri, 14 Nov 2014 00:47:19 -0800 Subject: [PATCH] object links: Added text marshaling --- core/commands2/ls.go | 13 ++++++++----- core/commands2/object.go | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/commands2/ls.go b/core/commands2/ls.go index d07a207e8..c849825de 100644 --- a/core/commands2/ls.go +++ b/core/commands2/ls.go @@ -82,11 +82,7 @@ it contains, with the following format: if len(output) > 1 { s += fmt.Sprintf("%s:\n", object.Hash) } - - for _, link := range object.Links { - s += fmt.Sprintf("%s %v %s\n", link.Hash, link.Size, link.Name) - } - + s += marshalLinks(object.Links) if len(output) > 1 { s += "\n" } @@ -97,3 +93,10 @@ it contains, with the following format: }, Type: &LsOutput{}, } + +func marshalLinks(links []Link) (s string) { + for _, link := range links { + s += fmt.Sprintf("%s %v %s\n", link.Hash, link.Size, link.Name) + } + return s +} diff --git a/core/commands2/object.go b/core/commands2/object.go index fdfc4dd2d..8263bdc20 100644 --- a/core/commands2/object.go +++ b/core/commands2/object.go @@ -108,6 +108,13 @@ It outputs to stdout, and is a base58 encoded multihash. return objectLinks(n, key) }, + Marshalers: cmds.MarshalerMap{ + cmds.Text: func(res cmds.Response) ([]byte, error) { + object := res.Output().(*Object) + marshalled := marshalLinks(object.Links) + return []byte(marshalled), nil + }, + }, Type: &Object{}, }