diff --git a/cmd/ipfs/pin.go b/cmd/ipfs/pin.go index fcebe6c4d..5919168b1 100644 --- a/cmd/ipfs/pin.go +++ b/cmd/ipfs/pin.go @@ -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) diff --git a/core/commands/pin.go b/core/commands/pin.go index 5dbbf6304..40b452ffa 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -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)