pin: add depth arg.

This commit is contained in:
Juan Batiz-Benet 2014-10-01 01:26:48 -07:00
parent 728f17d3c9
commit 14a384d826
2 changed files with 14 additions and 5 deletions

View File

@ -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)

View File

@ -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)