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
This commit is contained in:
Pascal Hartig
2019-06-04 07:40:01 -07:00
committed by Facebook Github Bot
parent b55ad41d97
commit eba84a7e08

View File

@@ -29,8 +29,8 @@ type UserArguments = {|
exit: 'sigint' | 'disconnect', exit: 'sigint' | 'disconnect',
verbose: boolean, verbose: boolean,
metrics: string, metrics: string,
showDevices: boolean, listDevices: boolean,
selectedDeviceID: string, device: string,
|}; |};
yargs yargs
@@ -40,13 +40,11 @@ yargs
'Start a headless Flipper instance', 'Start a headless Flipper instance',
yargs => { yargs => {
yargs.option('secure-port', { yargs.option('secure-port', {
alias: 'securePort',
default: '8088', default: '8088',
describe: 'Secure port the Flipper server should run on.', describe: 'Secure port the Flipper server should run on.',
type: 'string', type: 'string',
}); });
yargs.option('insecure-port', { yargs.option('insecure-port', {
alias: 'insecurePort',
default: '8089', default: '8089',
describe: 'Insecure port the Flipper server should run on.', describe: 'Insecure port the Flipper server should run on.',
type: 'string', type: 'string',
@@ -69,19 +67,16 @@ yargs
type: 'boolean', type: 'boolean',
}); });
yargs.option('metrics', { yargs.option('metrics', {
alias: 'metrics',
default: undefined, default: undefined,
describe: 'Will export metrics instead of data when flipper terminates', describe: 'Will export metrics instead of data when flipper terminates',
type: 'string', type: 'string',
}); });
yargs.option('list-devices', { yargs.option('list-devices', {
alias: 'showDevices',
default: false, default: false,
describe: 'Will print the list of devices in the terminal', describe: 'Will print the list of devices in the terminal',
type: 'boolean', type: 'boolean',
}); });
yargs.option('device', { yargs.option('device', {
alias: 'selectedDeviceID',
default: undefined, default: undefined,
describe: describe:
'The identifier passed will be matched against the udid of the available devices and the matched device would be selected', '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, userArguments: UserArguments,
originalConsole: typeof global.console, originalConsole: typeof global.console,
): Promise<void> { ): Promise<void> {
const {showDevices} = userArguments; if (userArguments.listDevices) {
if (showDevices) {
const devices = await listDevices(); const devices = await listDevices();
originalConsole.log(devices); originalConsole.log(devices);
process.exit(); process.exit();
@@ -158,7 +152,7 @@ async function storeModifyingActions(
originalConsole: typeof global.console, originalConsole: typeof global.console,
store: Store, store: Store,
): Promise<void> { ): Promise<void> {
const {selectedDeviceID} = userArguments; const {device: selectedDeviceID} = userArguments;
if (selectedDeviceID) { if (selectedDeviceID) {
//$FlowFixMe: Checked the class name before calling reverse. //$FlowFixMe: Checked the class name before calling reverse.
const devices = await listDevices(); const devices = await listDevices();