-
-
Notifications
You must be signed in to change notification settings - Fork 318
Expand file tree
/
Copy pathcommand_registry.go
More file actions
42 lines (36 loc) · 737 Bytes
/
Copy pathcommand_registry.go
File metadata and controls
42 lines (36 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/danielpaulus/go-ios/ios"
"github.com/docopt/docopt-go"
)
type commandContext struct {
Args docopt.Opts
Device ios.DeviceEntry
}
type command struct {
name string
match func(docopt.Opts) bool
run func(commandContext)
}
func boolArg(args docopt.Opts, name string) bool {
value, _ := args.Bool(name)
return value
}
func commandByBool(name string, run func(commandContext)) command {
return command{
name: name,
match: func(args docopt.Opts) bool {
return boolArg(args, name)
},
run: run,
}
}
func dispatchCommand(ctx commandContext, commands []command) bool {
for _, cmd := range commands {
if cmd.match(ctx.Args) {
cmd.run(ctx)
return true
}
}
return false
}