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',
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<void> {
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<void> {
const {selectedDeviceID} = userArguments;
const {device: selectedDeviceID} = userArguments;
if (selectedDeviceID) {
//$FlowFixMe: Checked the class name before calling reverse.
const devices = await listDevices();