提交 c7bc83e3 作者: palkeo

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

See #1086.

License: MIT
Signed-off-by: 's avatarpalkeo <contact@palkeo.com>
上级 72176379
......@@ -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()
......
......@@ -119,6 +119,9 @@ 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 {
......@@ -126,6 +129,12 @@ multihash.
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 {
......@@ -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)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论