Skip to content

Commit

Permalink
docs(advanced): document non-singleton use, .exit() and parsed (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall authored and bcoe committed Dec 19, 2018
1 parent 8789bf4 commit 54e165d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,12 @@ var argv = require('yargs')
)
.argv;
```

### Using the non-singleton interface

To use yargs without running as a singleton, do:
```
const argv = require('yargs/yargs')(process.argv.slice(2))
```

This is especially useful when using yargs in a library, as library authors should not pollute the global state.
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ uses the `.version` functionality, validation fails, or the command handler
fails. Calling `.exitProcess(false)` disables this behavior, enabling further
actions after yargs have been validated.

<a name="exit"></a>.exit(code, err)
---------
Manually indicate that the program should exit, and provide context about why we
wanted to exit. Follows the behaviour set by `.exitProcess()`.

<a name="fail"></a>.fail(fn)
---------

Expand Down Expand Up @@ -1136,6 +1141,13 @@ parser.parse(bot.userText, function (err, argv, output) {

***Note:*** Providing a callback to `parse()` disables the [`exitProcess` setting](#exitprocess) until after the callback is invoked.

<a name="parsed"></a>.parsed
------------
If the arguments have not been parsed, this property is `false`.

If the arguments have been parsed, this contain detailed parsed arguments. See
the documentation in [yargs-parser `.detailed()`][https://github.com/yargs/yargs-parser/blob/master/README.md#requireyargs-parserdetailedargs-opts]
for details of this object

<a name="pkg-conf"></a>
.pkgConf(key, [cwd])
Expand Down

0 comments on commit 54e165d

Please sign in to comment.