mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Merge pull request #2333 from palkeo/master
Add option to display headers for « ipfs object links ».
This commit is contained in:
commit
2600a0290a
@ -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(),
|
||||
},
|
||||
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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user