Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use commander to parse command-line options #650

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions react-native-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

var fs = require('fs');
var path = require('path');
var program = require('commander');
var spawn = require('child_process').spawn;

var CLI_MODULE_PATH = function() {
Expand All @@ -25,29 +26,22 @@ try {
if (cli) {
cli.run();
} else {
var args = process.argv.slice(2);
if (args.length === 0) {
console.error(
'You did not pass any commands, did you mean to run `react-native init`?'
);
program
.command('init <projectName>')
.description('create new React Native project with given name')
.action(init);

program.on('*', function(command) {
console.error('Unknown command: ' + command);
program.outputHelp();
process.exit(1);
}
});

if (args[0] === 'init') {
if (args[1]) {
init(args[1]);
} else {
console.error(
'Usage: react-native init <ProjectName>'
);
process.exit(1);
}
} else {
console.error(
'Command `%s` unrecognized. ' +
'Did you mean to run this inside a react-native project?',
args[0]
);
program.parse(process.argv);

if (!program.args.length) {
console.error('You did not pass any commands, did you mean to run `react-native init`?');
program.outputHelp();
process.exit(1);
}
}
Expand Down
3 changes: 3 additions & 0 deletions react-native-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"main": "index.js",
"bin": {
"react-native": "index.js"
},
"dependencies": {
"commander": "^2.7.x"
}
}