@cryptotaxi247 / kubo / commits / c7bc83e3d

Add option to display headers to "ipfs object links".

See #1086. License: MIT Signed-off-by: palkeo <contact@palkeo.com>

palkeo committed Feb 17, 2016 at 22:01 UTC c7bc83e3d69b2b08c7032b86a844e1c815f13895
2 files changed +14 -2
core/commands/ls.go
+1 -1
@@ -44,7 +44,7 @@ it contains, with the following format:
44 cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(),
45 },
46 Options: []cmds.Option{
47 - cmds.BoolOption("headers", "v", "Print table headers (Hash, Name, Size)."),
47 + cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
48 },
49 Run: func(req cmds.Request, res cmds.Response) {
50 node, err := req.InvocContext().GetNode()
core/commands/object/object.go
+13 -1
@@ -119,6 +119,9 @@ multihash.
119 Arguments: []cmds.Argument{
120 cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
121 },
122 + Options: []cmds.Option{
123 + cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
124 + },
125 Run: func(req cmds.Request, res cmds.Response) {
126 n, err := req.InvocContext().GetNode()
127 if err != nil {
@@ -126,6 +129,12 @@ multihash.
129 return
130 }
131
132 + // get options early -> exit early in case of error
133 + if _, _, err := req.Option("headers").Bool(); err != nil {
134 + res.SetError(err, cmds.ErrNormal)
135 + return
136 + }
137 +
138 fpath := path.Path(req.Arguments()[0])
139 node, err := core.Resolve(req.Context(), n, fpath)
140 if err != nil {
@@ -144,7 +153,10 @@ multihash.
153 object := res.Output().(*Object)
154 buf := new(bytes.Buffer)
155 w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
147 - fmt.Fprintln(w, "Hash\tSize\tName\t")
156 + headers, _, _ := res.Request().Option("headers").Bool()
157 + if headers {
158 + fmt.Fprintln(w, "Hash\tSize\tName\t")
159 + }
160 for _, link := range object.Links {
161 fmt.Fprintf(w, "%s\t%v\t%s\t\n", link.Hash, link.Size, link.Name)
162 }