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
This commit is contained in:
committed by
Facebook Github Bot
parent
565b8995ae
commit
bab2aaaf0e
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user