提交 2600a029 作者: Jeromy Johnson

Merge pull request #2333 from palkeo/master

Add option to display headers for « ipfs object links ».
...@@ -43,7 +43,7 @@ Displays the links an IPFS or IPNS object(s) contains, with the following format ...@@ -43,7 +43,7 @@ Displays the links an IPFS or IPNS object(s) contains, with the following format
cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(), cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(),
}, },
Options: []cmds.Option{ 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) { Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode() node, err := req.InvocContext().GetNode()
......
...@@ -119,6 +119,9 @@ multihash. ...@@ -119,6 +119,9 @@ multihash.
Arguments: []cmds.Argument{ Arguments: []cmds.Argument{
cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
if err != nil { if err != nil {
...@@ -126,6 +129,12 @@ multihash. ...@@ -126,6 +129,12 @@ multihash.
return 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]) fpath := path.Path(req.Arguments()[0])
node, err := core.Resolve(req.Context(), n, fpath) node, err := core.Resolve(req.Context(), n, fpath)
if err != nil { if err != nil {
...@@ -144,7 +153,10 @@ multihash. ...@@ -144,7 +153,10 @@ multihash.
object := res.Output().(*Object) object := res.Output().(*Object)
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0) 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 { for _, link := range object.Links {
fmt.Fprintf(w, "%s\t%v\t%s\t\n", link.Hash, link.Size, link.Name) fmt.Fprintf(w, "%s\t%v\t%s\t\n", link.Hash, link.Size, link.Name)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论