react-native/packager/parseCommandLine.js
Christopher Chedeau 5baffa03fd Second Updates from Mon 23 Mar
- [ReactNative] Use deprecated ix in TabBarExample | Amjad Masad
- [ReactNative] Expanded license on obj-c files | Christopher Chedeau
- [ReactNative] Expanded license on js files | Christopher Chedeau
- [ReactNative] Fix React Devtools integration | Alex Kotliarskyi
- [Text] Account for font leading so descenders are not clipped | James Ide
- [ReactNative] Expanded license on js packager files | Christopher Chedeau
- more UIExplorer flow | Basil Hosmer
- [react-packager] Pick up package changes while running | Amjad Masad
- Added a graph view and a ReactNative metric that displays current queue and execution time for the JS thread. | Bryce Redd
- [ReactNative] Add NativeModules and DeviceEventEmitter to react-native exports | Alex Kotliarskyi
2015-03-23 15:07:33 -07:00

58 lines
1.6 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Wrapper on-top of `optimist` in order to properly support boolean flags
* and have a slightly less akward API.
*
* Usage example:
* var argv = parseCommandLine([{
* command: 'web',
* description: 'Run in a web browser instead of iOS',
* default: true
* }])
*/
'use strict';
var optimist = require('optimist');
function parseCommandLine(config) {
// optimist default API requires you to write the command name three time
// This is a small wrapper to accept an object instead
for (var i = 0; i < config.length; ++i) {
optimist
.boolean(config[i].command)
.default(config[i].command, config[i].default)
.describe(config[i].command, config[i].description);
}
var argv = optimist.argv;
// optimist doesn't have support for --dev=false, instead it returns 'false'
for (var i = 0; i < config.length; ++i) {
var command = config[i].command;
if (argv[command] === undefined) {
argv[command] = config[i].default;
}
if (argv[command] === 'true') {
argv[command] = true;
}
if (argv[command] === 'false') {
argv[command] = false;
}
}
// Show --help
if (argv.help || argv.h) {
optimist.showHelp();
process.exit();
}
return argv;
}
module.exports = parseCommandLine;