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

docs(api): clarify process.argv handling and the order of API methods #1644

Merged
merged 3 commits into from Jun 6, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/api.md
Expand Up @@ -20,7 +20,7 @@ best to parse `process.argv`:
require('yargs').argv
```

You can also pass in the `process.argv` yourself:
You can also pass in the arguments yourself:

```javascript
require('yargs')([ '-x', '1', '-y', '2' ]).argv
Expand All @@ -38,7 +38,15 @@ Calling `.parse()` with no arguments is equivalent to calling `yargs.argv`:
require('yargs').parse()
```

The rest of these methods below come in just before the terminating `.argv`.
When passing in the arguments yourself, note that Yargs expects the passed array
to contain only the arguments after the program name, while Node’s
mleguen marked this conversation as resolved.
Show resolved Hide resolved
[`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array
starts with two extra elements:`process.execPath` and the path to the JavaScript
file being executed. So if you’re getting your arguments from `process.argv`,
pass `process.argv.slice(2)` to Yargs.

The rest of these methods below come in just before the terminating `.argv` or
terminating `.parse()`.

<a name="alias"></a>.alias(key, alias)
------------------
Expand Down