提交 9de01007 作者: Matt Bell

core/commands: pin ls: Accept 'type' option to specify type of pinned keys to list

上级 e6091be0
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
cmds "github.com/jbenet/go-ipfs/commands" cmds "github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core" "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/merkledag" "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util"
) )
var pinCmd = &cmds.Command{ var pinCmd = &cmds.Command{
...@@ -109,15 +110,39 @@ or recursively pinned are not included in the list. ...@@ -109,15 +110,39 @@ or recursively pinned are not included in the list.
`, `,
}, },
Options: []cmds.Option{
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\""),
},
Run: func(req cmds.Request) (interface{}, error) { Run: func(req cmds.Request) (interface{}, error) {
n, err := req.Context().GetNode() n, err := req.Context().GetNode()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &KeyList{ typeStr, found, err := req.Option("type").String()
Keys: n.Pinning.Set().GetKeys(), if err != nil {
}, nil return nil, err
}
if !found {
typeStr = "all"
}
if typeStr != "all" && typeStr != "direct" && typeStr != "indirect" && typeStr != "recursive" {
return nil, cmds.ClientError("Invalid type '" + typeStr + "', must be \"direct\", \"indirect\", \"recursive\", or \"all\"")
}
keys := make([]u.Key, 0)
if typeStr == "direct" || typeStr == "all" {
keys = append(keys, n.Pinning.DirectKeys()...)
}
if typeStr == "indirect" || typeStr == "all" {
keys = append(keys, n.Pinning.IndirectKeys()...)
}
if typeStr == "recursive" || typeStr == "all" {
keys = append(keys, n.Pinning.RecursiveKeys()...)
}
return &KeyList{Keys: keys}, nil
}, },
Type: &KeyList{}, Type: &KeyList{},
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论