forked from danielpaulus/go-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_global.go
More file actions
67 lines (61 loc) · 2.15 KB
/
Copy pathcmd_global.go
File metadata and controls
67 lines (61 loc) · 2.15 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import "github.com/docopt/docopt-go"
var preProxyCommands = []command{
{
name: "version",
match: func(args docopt.Opts) bool {
return boolArg(args, "version") || boolArg(args, "--version")
},
run: func(ctx commandContext) {
printVersion()
},
},
}
var globalCommands = []command{
{
name: "ui",
match: func(args docopt.Opts) bool {
// `ui install` and `ui run` need a device, so they are device
// commands; everything else under `ui` is a URL-based client command.
return boolArg(args, "ui") && !boolArg(args, "install") && !boolArg(args, "run")
},
run: runUICommand,
},
commandByBool("listen", runListenCommand),
{
name: "list",
match: isDeviceListCommand,
run: runDeviceListCommand,
},
{
// `sign certificate appstoreconnect` mints an account-wide certificate and
// needs no device, so it is global (dispatched before device resolution).
name: "sign certificate",
match: func(args docopt.Opts) bool {
return boolArg(args, "sign") && boolArg(args, "certificate")
},
run: runSignCertificateAppStoreConnectCommand,
},
}
func runListenCommand(ctx commandContext) {
startListening()
}
// isDeviceListCommand matches the bare global `ios list`. globalCommands are
// dispatched before deviceCommands, so every device subcommand that also has a
// `list` literal (`ios <cmd> list`) sets the same "list" arg and would otherwise
// be swallowed here. Each such command must be excluded below;
// TestDeviceListCommandOnlyMatchesTopLevelList guards that every `<cmd> list`
// subcommand is excluded rather than falling through to the device list.
func isDeviceListCommand(args docopt.Opts) bool {
listCommand := boolArg(args, "list")
diagnosticsCommand := boolArg(args, "diagnostics")
imageCommand := boolArg(args, "image")
deviceStateCommand := boolArg(args, "devicestate")
profileCommand := boolArg(args, "profile")
webInspectorCommand := boolArg(args, "webinspector")
return listCommand && !diagnosticsCommand && !imageCommand && !deviceStateCommand && !profileCommand && !webInspectorCommand
}
func runDeviceListCommand(ctx commandContext) {
details, _ := ctx.Args.Bool("--details")
printDeviceList(details)
}