Skip to content

Commit

Permalink
use the builtin option parser to set the default for `ipfs pin ls --t…
Browse files Browse the repository at this point in the history
…ype`

License: MIT
Signed-off-by: Steven Allen <[email protected]>
  • Loading branch information
Stebalien committed Mar 16, 2016
1 parent ffb8d53 commit bc1586f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Example:
cmds.StringArg("ipfs-path", false, true, "Path to object(s) to be listed."),
},
Options: []cmds.Option{
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"recursive\"."),
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\".").Default("all"),
cmds.BoolOption("count", "n", "Show refcount when listing indirect pins."),
cmds.BoolOption("quiet", "q", "Write just hashes of objects."),
},
Expand All @@ -198,22 +198,18 @@ Example:
return
}

typeStr, typeStrFound, err := req.Option("type").String()
typeStr, _, err := req.Option("type").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

if typeStrFound {
switch typeStr {
case "all", "direct", "indirect", "recursive":
default:
err = fmt.Errorf("Invalid type '%s', must be one of {direct, indirect, recursive, all}", typeStr)
res.SetError(err, cmds.ErrClient)
return
}
} else {
typeStr = "all"
switch typeStr {
case "all", "direct", "indirect", "recursive":
default:
err = fmt.Errorf("Invalid type '%s', must be one of {direct, indirect, recursive, all}", typeStr)
res.SetError(err, cmds.ErrClient)
return
}

var keys map[string]RefKeyObject
Expand Down

0 comments on commit bc1586f

Please sign in to comment.