mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-05 16:28:06 +08:00
pin: add depth arg.
This commit is contained in:
parent
728f17d3c9
commit
14a384d826
@ -20,6 +20,7 @@ var cmdIpfsPin = &commander.Command{
|
||||
|
||||
func init() {
|
||||
cmdIpfsPin.Flag.Bool("r", false, "pin objects recursively")
|
||||
cmdIpfsPin.Flag.Int("d", 1, "recursive depth")
|
||||
}
|
||||
|
||||
var pinCmd = MakeCommand("pin", []string{"r"}, commands.Pin)
|
||||
var pinCmd = MakeCommand("pin", []string{"r", "d"}, commands.Pin)
|
||||
|
||||
@ -9,11 +9,19 @@ import (
|
||||
|
||||
func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
|
||||
|
||||
// if recursive, set flag
|
||||
depth := 1
|
||||
if r, ok := opts["r"].(bool); r && ok {
|
||||
depth = -1
|
||||
// set recursive flag
|
||||
recursive, _ := opts["r"].(bool) // false if cast fails.
|
||||
|
||||
// if recursive, set depth flag
|
||||
depth := 1 // default (non recursive)
|
||||
if d, ok := opts["d"].(int); recursive && ok {
|
||||
depth = d
|
||||
}
|
||||
if depth < -1 {
|
||||
return fmt.Errorf("ipfs pin: called with invalid depth: %v", depth)
|
||||
}
|
||||
|
||||
fmt.Printf("recursive, depth: %v, %v\n", recursive, depth)
|
||||
|
||||
for _, fn := range args {
|
||||
dagnode, err := n.Resolver.ResolvePath(fn)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user