From eba84a7e08047bb5dc2017c6744ab740771b7254 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 4 Jun 2019 07:40:01 -0700 Subject: [PATCH] Reorganize CLI arguments Summary: 1. Yargs doesn't like having the same option name as the given alias and will just silently skip those (like --metrics). 2. Having multiple ways of specifying the same argument is not a good practise. I think we've been misusing `alias` as a way to have more JavaScript-y accessors, but ignoring that yargs already converts `my-long-argument` to `myLongArgument` without having to expose this. We haven't rolled out a version with the previous long arguments, so we should still be able to change this without breaking stuff. Reviewed By: jknoxville Differential Revision: D15620636 fbshipit-source-id: 84a8046cf06d696e947719032c4f9c34ac9c0474 --- headless/index.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/headless/index.js b/headless/index.js index 5948de082..13636b05a 100644 --- a/headless/index.js +++ b/headless/index.js @@ -29,8 +29,8 @@ type UserArguments = {| exit: 'sigint' | 'disconnect', verbose: boolean, metrics: string, - showDevices: boolean, - selectedDeviceID: string, + listDevices: boolean, + device: string, |}; yargs @@ -40,13 +40,11 @@ yargs 'Start a headless Flipper instance', yargs => { yargs.option('secure-port', { - alias: 'securePort', default: '8088', describe: 'Secure port the Flipper server should run on.', type: 'string', }); yargs.option('insecure-port', { - alias: 'insecurePort', default: '8089', describe: 'Insecure port the Flipper server should run on.', type: 'string', @@ -69,19 +67,16 @@ yargs type: 'boolean', }); yargs.option('metrics', { - alias: 'metrics', default: undefined, describe: 'Will export metrics instead of data when flipper terminates', type: 'string', }); yargs.option('list-devices', { - alias: 'showDevices', default: false, 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', @@ -104,8 +99,7 @@ async function earlyExitActions( userArguments: UserArguments, originalConsole: typeof global.console, ): Promise { - const {showDevices} = userArguments; - if (showDevices) { + if (userArguments.listDevices) { const devices = await listDevices(); originalConsole.log(devices); process.exit(); @@ -158,7 +152,7 @@ async function storeModifyingActions( originalConsole: typeof global.console, store: Store, ): Promise { - const {selectedDeviceID} = userArguments; + const {device: selectedDeviceID} = userArguments; if (selectedDeviceID) { //$FlowFixMe: Checked the class name before calling reverse. const devices = await listDevices();