Skip to content

Commit

Permalink
Add option to display headers to "ipfs object links".
Browse files Browse the repository at this point in the history
See #1086.

License: MIT
Signed-off-by: palkeo <contact@palkeo.com>
  • Loading branch information
palkeo committed Feb 17, 2016
1 parent 7217637 commit c7bc83e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ it contains, with the following format:
cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Name, Size)."),
cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
Expand Down
14 changes: 13 additions & 1 deletion core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@ multihash.
Arguments: []cmds.Argument{
cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

// get options early -> exit early in case of error
if _, _, err := req.Option("headers").Bool(); err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

fpath := path.Path(req.Arguments()[0])
node, err := core.Resolve(req.Context(), n, fpath)
if err != nil {
Expand All @@ -144,7 +153,10 @@ multihash.
object := res.Output().(*Object)
buf := new(bytes.Buffer)
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
fmt.Fprintln(w, "Hash\tSize\tName\t")
headers, _, _ := res.Request().Option("headers").Bool()
if headers {
fmt.Fprintln(w, "Hash\tSize\tName\t")
}
for _, link := range object.Links {
fmt.Fprintf(w, "%s\t%v\t%s\t\n", link.Hash, link.Size, link.Name)
}
Expand Down

0 comments on commit c7bc83e

Please sign in to comment.