Skip to content

Commit c2481a8

Browse files
author
Assad Ginem
committed
adding map for commands that require/dont require tunnel to avoid checking several times or failure
1 parent 6a94ebe commit c2481a8

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

main.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ var (
5858
prettyJSON = false
5959
)
6060

61+
// Commands that require tunnel info
62+
var commandsRequiringTunnel = map[string]bool{
63+
"image mount": true,
64+
"reboot": false,
65+
"batterycheck": false,
66+
"devmode": false,
67+
"diskspace": false,
68+
"uninstall": false,
69+
"install": false,
70+
"apps": false,
71+
"info": false,
72+
"readpair": false,
73+
"lang": false,
74+
}
75+
76+
func requiresTunnel(arguments map[string]interface{}) bool {
77+
for cmd, needsTunnel := range commandsRequiringTunnel {
78+
if needsTunnel {
79+
if b, _ := arguments[cmd].(bool); b {
80+
return true
81+
}
82+
}
83+
}
84+
return false
85+
}
86+
6187
func main() {
6288
Main()
6389
}
@@ -315,17 +341,20 @@ The commands work as following:
315341
rsdPort, rsdErr := arguments.Int("--rsd-port")
316342

317343
device, err := ios.GetDevice(udid)
318-
// device address and rsd port are only available after the tunnel started
319-
if !tunnelCommand {
320-
exitIfError("Device not found: "+udid, err)
321-
if addressErr == nil && rsdErr == nil {
322-
device = deviceWithRsdProvider(device, udid, address, rsdPort)
323-
} else {
324-
info, err := tunnel.TunnelInfoForDevice(device.Properties.SerialNumber, tunnelInfoPort)
325-
if err == nil {
326-
device = deviceWithRsdProvider(device, udid, info.Address, info.RsdPort)
344+
// Check if the command requires tunnel info
345+
if requiresTunnel(arguments) {
346+
// device address and rsd port are only available after the tunnel started
347+
if !tunnelCommand {
348+
exitIfError("Device not found: "+udid, err)
349+
if addressErr == nil && rsdErr == nil {
350+
device = deviceWithRsdProvider(device, udid, address, rsdPort)
327351
} else {
328-
log.WithField("udid", device.Properties.SerialNumber).Warn("failed to get tunnel info")
352+
info, err := tunnel.TunnelInfoForDevice(device.Properties.SerialNumber, tunnelInfoPort)
353+
if err == nil {
354+
device = deviceWithRsdProvider(device, udid, info.Address, info.RsdPort)
355+
} else {
356+
log.WithField("udid", device.Properties.SerialNumber).Warn("failed to get tunnel info")
357+
}
329358
}
330359
}
331360
}

0 commit comments

Comments
 (0)