|
58 | 58 | prettyJSON = false
|
59 | 59 | )
|
60 | 60 |
|
| 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 | + |
61 | 87 | func main() {
|
62 | 88 | Main()
|
63 | 89 | }
|
@@ -315,17 +341,20 @@ The commands work as following:
|
315 | 341 | rsdPort, rsdErr := arguments.Int("--rsd-port")
|
316 | 342 |
|
317 | 343 | 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) |
327 | 351 | } 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 | + } |
329 | 358 | }
|
330 | 359 | }
|
331 | 360 | }
|
|
0 commit comments