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 <ProjectName> [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
This commit is contained in:
Fahrradflucht 2016-11-11 23:47:51 -08:00 committed by Facebook Github Bot
parent 9910d8301b
commit 9c667f2968
1 changed files with 20 additions and 1 deletions

View File

@ -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 <ProjectName> [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);
}