Skip to content

Commit eb68921

Browse files
author
Anand Thakker
committed
Safely reset yargs
1 parent b3c990d commit eb68921

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/args.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var documentation = require('../'),
22
path = require('path'),
33
loadConfig = require('../lib/load_config.js');
4-
54
var yargs = require('yargs')
6-
.reset()
5+
6+
function parse() {
7+
// reset() needs to be called at parse time because the yargs module uses an
8+
// internal global variable to hold option state
9+
return yargs.reset()
710
.usage('Usage: $0 <command> [options]')
811

912
.option('f', {
@@ -52,16 +55,19 @@ var yargs = require('yargs')
5255
.help('h')
5356
.alias('h', 'help')
5457

55-
.example('$0 foo.js', 'parse documentation in a given file');
58+
.example('$0 foo.js', 'parse documentation in a given file')
5659

60+
.parse(args)
61+
62+
}
5763
/**
5864
* Parse and validate command-line options for documentation.
5965
* @param {Array} args The array of arguments to parse; e.g. process.argv.slice(2).
6066
* @return {object} {inputs, options, formatter, formatterOptions, output}
6167
* @private
6268
*/
6369
module.exports = function (args) {
64-
var argv = yargs.parse(args);
70+
var argv = parse(args);
6571

6672
var inputs,
6773
name = argv.name,

0 commit comments

Comments
 (0)