-
Notifications
You must be signed in to change notification settings - Fork 25k
Fix help information for react-native-cli commands #9173
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
Conversation
The high level `react-native --help` command works okay, but using `react-native command --help` seems to be broken. It works for some commands that have basic usage (i.e., options only, including run-android and run-ios), but it does not work for commands that have optional arguments in their usage, like `react-native link --help`. This fixes commands like `react-native link`, although it deletes some behavior that I'm not quite sure what the original intent was (cc author @grabbou).
|
By analyzing the blame information on this pull request, we identified @grabbou and @janicduplessis to be potential reviewers. |
|
@grabbou definitely want your input here. I deleted this bit: const usage = this.usage();
if (usage !== '[options]') {
const formattedUsage = usage.map(
example => ` ${example.desc}: \n ${chalk.cyan(example.cmd)}`,
).join('\n\n');
output = output.concat([
chalk.bold(' Example usage:'),
'',
formattedUsage,
]);
} Because I didn't know what you were trying to do. |
|
It meant to display a proper --help message with examples. Not sure if it works after merge (we checked only command functionality). Probably a better way would be to fix an original behavior. |
|
@Kureev Do you know how to add examples to a commander Command instance? I didn't see anything of the sort in the commander documentation. |
|
We added them as a help (usage) message. Every command has a structure, described here. So the mapping you removed is for the example usage message. It formats a nice message and outputs it as a "usage" info. |
|
@Kureev okay, I'll publish another update, I think it may have just been a bug, where the output from usage was being used instead of examples. |
|
@rozele updated the pull request. |
|
@Kureev I added what I expect is the correct behavior for examples, however, there are currently no documented react-native commands that have examples. Also, that exported type is never being used. The architecture is currently using the Command prototype from commander (https://github.com/tj/commander.js/blob/master/index.js#L82), which has no examples. When you parse the declaration of each command, even if it has an At this point, I would actually recommend reverting my second commit and just deleting the examples stuff as I had in the first commit. cc @grabbou |
|
@rozele currently We were never adding custom Now, to make it easier, we pass an array of examples to Later, we check if it's Check the example docs here https://github.com/facebook/react-native/blob/master/local-cli/runIOS/runIOS.js#L84-L93 |
When an `examples` property is present, the command is assumed to not take any additional command line arguments (i.e., the usage is `[options]` only), and the return value of `.usage()` is an array of examples. This provides a proper check for the result of `cmd.usage()` to be a string (the normal case when examples are not present), in which case the set of examples are not processed. Prior to this change, running `react-native link --help` would result in an exception, because the `.usage()` output for `link` is `[options] [packageName]` (note, !== `[options]`). In general, overriding the behavior of usage() may be limiting, as this change will not support adding examples to `react-native link --help` while still allowing the first line of the --help message to include the original usage (`[options] [packageName]`).
|
@rozele updated the pull request. |
|
@rozele updated the pull request. |
|
@grabbou, check the description of the most recent commit in this PR, specifically: This provides a proper check for the result of Prior to this change, running In general, overriding the behavior of usage() may be limiting, as this change will not support adding examples to |
|
|
||
| const usage = this.usage(); | ||
| const usageIsString = typeof(usage) === 'string'; | ||
| const usageString = usageIsString ? usage : '[options]'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's going to be an issue with this eventually. For example, how does one add an examples section to the link command? If you did add examples, you'd lose the original usage() value ([options] [packageName]).

The high level
react-native --helpcommand works okay, but usingreact-native command --helpseems to be broken. It works for some commands that have basic usage (i.e., options only, including run-android and run-ios), but it does not work for commands that have optional arguments in their usage, likereact-native link --help.This fixes commands like
react-native link, although it deletes some behavior that I'm not quite sure what the original intent was (cc author @grabbou).