core/commands: Added more advanced test subcommand
Matt Bell committed
Oct 22, 2014 at 16:02 UTC
3d0ca14b96ff21ac614365ab9ecd39a91eb4b176
1 file changed
+20
core/commands/root.go
+20
@@ -1,6 +1,7 @@
1
package commands
2
3
import (
4
+ "fmt"
5
cmds "github.com/jbenet/go-ipfs/commands"
6
"strings"
7
)
@@ -52,5 +53,24 @@ Use "ipfs help <command>" for more information about a command.
53
res.SetValue(v)
54
},
55
},
56
+ "warp": &cmds.Command{
57
+ Options: []cmds.Option{
58
+ cmds.Option{[]string{"power", "p"}, cmds.Float},
59
+ },
60
+ Run: func(req cmds.Request, res cmds.Response) {
61
+ threshold := 1.21
62
+
63
+ if power, found := req.Option("power"); found && power.(float64) >= threshold {
64
+ res.SetValue(struct {
65
+ Status string
66
+ Power float64
67
+ }{"Flux capacitor activated!", power.(float64)})
68
+
69
+ } else {
70
+ err := fmt.Errorf("Insufficient power (%v jiggawatts required)", threshold)
71
+ res.SetError(err, cmds.ErrClient)
72
+ }
73
+ },
74
+ },
75
},
76
}