object links: Added text marshaling
Matt Bell committed
Nov 14, 2014 at 00:47 UTC
b3da13a4afb97c97f0acb1bea7954260b20e7721
2 files changed
+15
-5
core/commands2/ls.go
+8
-5
@@ -82,11 +82,7 @@ it contains, with the following format:
82
if len(output) > 1 {
83
s += fmt.Sprintf("%s:\n", object.Hash)
84
}
85
-
86
- for _, link := range object.Links {
87
- s += fmt.Sprintf("%s %v %s\n", link.Hash, link.Size, link.Name)
88
- }
89
-
85
+ s += marshalLinks(object.Links)
86
if len(output) > 1 {
87
s += "\n"
88
}
@@ -97,3 +93,10 @@ it contains, with the following format:
93
},
94
Type: &LsOutput{},
95
}
96
+
97
+func marshalLinks(links []Link) (s string) {
98
+ for _, link := range links {
99
+ s += fmt.Sprintf("%s %v %s\n", link.Hash, link.Size, link.Name)
100
+ }
101
+ return s
102
+}
core/commands2/object.go
+7
@@ -108,6 +108,13 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
108
109
return objectLinks(n, key)
110
},
111
+ Marshalers: cmds.MarshalerMap{
112
+ cmds.Text: func(res cmds.Response) ([]byte, error) {
113
+ object := res.Output().(*Object)
114
+ marshalled := marshalLinks(object.Links)
115
+ return []byte(marshalled), nil
116
+ },
117
+ },
118
Type: &Object{},
119
}
120