From 9c667f29688158727f2b02f4a8954e2018423ea0 Mon Sep 17 00:00:00 2001 From: Fahrradflucht Date: Fri, 11 Nov 2016 23:47:51 -0800 Subject: [PATCH] Add help option to react-native-cli Summary: This PR fixes #10784 by adding a `--help` and a `-h` option to `react-native-cli`. **Test plan:** Publish to sinopia and then outside of `react-native` project: ``` $ react-native --help #same goes for -h Usage: react-native [command] [options] Commands: init [options] generates a new project and installs its dependencies Options: -h, --help output usage information -v, --version output the version number ``` ``` $ react-native You did not pass any commands, run `react-native --help` to see a list of all available commands. ``` **Notes:** - There is no real consistency in the UX for `react-native-cli` and `local-cli` and even is no real consistency between the UI of `react-native [command] --help` and `react-native --help` in `local-cli` either. I tried to resemble the UX of `react-native --help` as close as possible since it's kind of the nearest neighbour. - This *doesn't* add support for `react-native init --help` in `react-na Closes https://github.com/facebook/react-native/pull/10828 Differential Revision: D4168266 Pulled By: hramos fbshipit-source-id: 079917622bf5b22a3cd6414f13865c1b9c01da01 --- react-native-cli/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/react-native-cli/index.js b/react-native-cli/index.js index fa1e5fc4e..db24b5780 100755 --- a/react-native-cli/index.js +++ b/react-native-cli/index.js @@ -115,9 +115,28 @@ var commands = argv._; if (cli) { cli.run(); } else { + if (argv._.length === 0 && (argv.h || argv.help)) { + console.log([ + '', + ' Usage: react-native [command] [options]', + '', + '', + ' Commands:', + '', + ' init [options] generates a new project and installs its dependencies', + '', + ' Options:', + '', + ' -h, --help output usage information', + ' -v, --version output the version number', + '', + ].join('\n')); + process.exit(0); + } + if (commands.length === 0) { console.error( - 'You did not pass any commands, did you mean to run `react-native init`?' + 'You did not pass any commands, run `react-native --help` to see a list of all available commands.' ); process.exit(1); }