From bab2aaaf0e9b759192f12b517415891398ff8fe4 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 30 May 2019 08:28:00 -0700 Subject: [PATCH] Select device in headless Summary: Adds an argument to select a device in headless. I will refactor the function the headless function in the next diff Reviewed By: danielbuechele Differential Revision: D15536774 fbshipit-source-id: 2e3f01c6bc6094d925aebd20ba0bf15b17168cd1 --- headless/index.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/headless/index.js b/headless/index.js index 49d430df7..9ed94eae2 100644 --- a/headless/index.js +++ b/headless/index.js @@ -66,6 +66,13 @@ yargs describe: 'Will print the list of devices in the terminal', type: 'boolean', }); + yargs.option('device', { + alias: 'selectedDeviceID', + default: undefined, + describe: + 'The identifier passed will be matched against the udid of the available devices and the matched device would be selected', + type: 'string', + }); }, startFlipper, ) @@ -84,6 +91,7 @@ async function startFlipper({ verbose, metrics, showDevices, + selectedDeviceID, exit, 'insecure-port': insecurePort, 'secure-port': securePort, @@ -171,6 +179,31 @@ async function startFlipper({ process.exit(); } + if (selectedDeviceID) { + //$FlowFixMe: Checked the class name before calling reverse. + const devices = await listDevices(); + const matchedDevice = devices.find( + device => device.serial === selectedDeviceID, + ); + if (matchedDevice) { + if (matchedDevice.constructor.name === 'AndroidDevice') { + const ports = store.getState().application.serverPorts; + matchedDevice.reverse([ports.secure, ports.insecure]); + } + store.dispatch({ + type: 'REGISTER_DEVICE', + payload: matchedDevice, + }); + store.dispatch({ + type: 'SELECT_DEVICE', + payload: matchedDevice, + }); + } else { + console.error(`No device matching the serial ${selectedDeviceID}`); + process.exit(); + } + } + if (exit == 'sigint') { process.on('SIGINT', async () => { try {