@cryptotaxi247 / kubo / commits / 14a384d82

pin: add depth arg.

Juan Batiz-Benet committed Oct 1, 2014 at 01:26 UTC 14a384d82679b3efcd708d9694575d93adf310cb
2 files changed +14 -5
cmd/ipfs/pin.go
+2 -1
@@ -20,6 +20,7 @@ var cmdIpfsPin = &commander.Command{
20
21 func init() {
22 cmdIpfsPin.Flag.Bool("r", false, "pin objects recursively")
23 + cmdIpfsPin.Flag.Int("d", 1, "recursive depth")
24 }
25
25 -var pinCmd = MakeCommand("pin", []string{"r"}, commands.Pin)
26 +var pinCmd = MakeCommand("pin", []string{"r", "d"}, commands.Pin)
core/commands/pin.go
+12 -4
@@ -9,12 +9,20 @@ import (
9
10 func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11
12 - // if recursive, set flag
13 - depth := 1
14 - if r, ok := opts["r"].(bool); r && ok {
15 - depth = -1
12 + // set recursive flag
13 + recursive, _ := opts["r"].(bool) // false if cast fails.
14 +
15 + // if recursive, set depth flag
16 + depth := 1 // default (non recursive)
17 + if d, ok := opts["d"].(int); recursive && ok {
18 + depth = d
19 + }
20 + if depth < -1 {
21 + return fmt.Errorf("ipfs pin: called with invalid depth: %v", depth)
22 }
23
24 + fmt.Printf("recursive, depth: %v, %v\n", recursive, depth)
25 +
26 for _, fn := range args {
27 dagnode, err := n.Resolver.ResolvePath(fn)
28 if err != nil {