Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / node_modules / yargs / README.md
1 yargs
2 ========
3
4 Yargs be a node.js library fer hearties tryin' ter parse optstrings.
5
6 With yargs, ye be havin' a map that leads straight to yer treasure! Treasure of course, being a simple option hash.
7
8 [![Build Status][travis-image]][travis-url]
9 [![Dependency Status][gemnasium-image]][gemnasium-url]
10 [![Coverage Status][coveralls-image]][coveralls-url]
11 [![NPM version][npm-image]][npm-url]
12 [![Windows Tests][windows-image]][windows-url]
13
14 > Yargs is the official successor to optimist. Please feel free to submit issues and pull requests. If you'd like to contribute and don't know where to start, have a look at [the issue list](https://github.com/bcoe/yargs/issues) :)
15
16 examples
17 ========
18
19 With yargs, the options be just a hash!
20 -------------------------------------------------------------------
21
22 plunder.js:
23
24 ````javascript
25 #!/usr/bin/env node
26 var argv = require('yargs').argv;
27
28 if (argv.ships > 3 && argv.distance < 53.5) {
29     console.log('Plunder more riffiwobbles!');
30 }
31 else {
32     console.log('Retreat from the xupptumblers!');
33 }
34 ````
35
36 ***
37
38     $ ./plunder.js --ships=4 --distance=22
39     Plunder more riffiwobbles!
40
41     $ ./plunder.js --ships 12 --distance 98.7
42     Retreat from the xupptumblers!
43
44 ![Joe was one optimistic pirate.](http://i.imgur.com/4WFGVJ9.png)
45
46 But don't walk the plank just yet! There be more! You can do short options:
47 -------------------------------------------------
48
49 short.js:
50
51 ````javascript
52 #!/usr/bin/env node
53 var argv = require('yargs').argv;
54 console.log('(%d,%d)', argv.x, argv.y);
55 ````
56
57 ***
58
59     $ ./short.js -x 10 -y 21
60     (10,21)
61
62 And booleans, both long, short, and even grouped:
63 ----------------------------------
64
65 bool.js:
66
67 ````javascript
68 #!/usr/bin/env node
69 var argv = require('yargs').argv;
70
71 if (argv.s) {
72     process.stdout.write(argv.fr ? 'Le perroquet dit: ' : 'The parrot says: ');
73 }
74 console.log(
75     (argv.fr ? 'couac' : 'squawk') + (argv.p ? '!' : '')
76 );
77 ````
78
79 ***
80
81     $ ./bool.js -s
82     The parrot says: squawk
83
84     $ ./bool.js -sp
85     The parrot says: squawk!
86
87     $ ./bool.js -sp --fr
88     Le perroquet dit: couac!
89
90 And non-hyphenated options too! Just use `argv._`!
91 -------------------------------------------------
92
93 nonopt.js:
94
95 ````javascript
96 #!/usr/bin/env node
97 var argv = require('yargs').argv;
98 console.log('(%d,%d)', argv.x, argv.y);
99 console.log(argv._);
100 ````
101
102 ***
103
104     $ ./nonopt.js -x 6.82 -y 3.35 rum
105     (6.82,3.35)
106     [ 'rum' ]
107
108     $ ./nonopt.js "me hearties" -x 0.54 yo -y 1.12 ho
109     (0.54,1.12)
110     [ 'me hearties', 'yo', 'ho' ]
111
112 Yargs even counts your booleans!
113 ----------------------------------------------------------------------
114
115 count.js:
116
117 ````javascript
118 #!/usr/bin/env node
119 var argv = require('yargs')
120     .count('verbose')
121     .alias('v', 'verbose')
122     .argv;
123
124 VERBOSE_LEVEL = argv.verbose;
125
126 function WARN()  { VERBOSE_LEVEL >= 0 && console.log.apply(console, arguments); }
127 function INFO()  { VERBOSE_LEVEL >= 1 && console.log.apply(console, arguments); }
128 function DEBUG() { VERBOSE_LEVEL >= 2 && console.log.apply(console, arguments); }
129
130 WARN("Showing only important stuff");
131 INFO("Showing semi-important stuff too");
132 DEBUG("Extra chatty mode");
133 ````
134
135 ***
136     $ node count.js
137     Showing only important stuff
138
139     $ node count.js -v
140     Showing only important stuff
141     Showing semi-important stuff too
142
143     $ node count.js -vv
144     Showing only important stuff
145     Showing semi-important stuff too
146     Extra chatty mode
147
148     $ node count.js -v --verbose
149     Showing only important stuff
150     Showing semi-important stuff too
151     Extra chatty mode
152
153 Tell users how to use yer options and make demands.
154 -------------------------------------------------
155
156 area.js:
157
158 ````javascript
159 #!/usr/bin/env node
160 var argv = require('yargs')
161     .usage('Usage: $0 -w [num] -h [num]')
162     .demand(['w','h'])
163     .argv;
164
165 console.log("The area is:", argv.w * argv.h);
166 ````
167
168 ***
169
170     $ ./area.js -w 55 -h 11
171     The area is: 605
172
173     $ node ./area.js -w 4.91 -w 2.51
174     Usage: area.js -w [num] -h [num]
175
176     Options:
177       -w  [required]
178       -h  [required]
179
180     Missing required arguments: h
181
182 After yer demands have been met, demand more! Ask for non-hyphenated arguments!
183 -----------------------------------------
184
185 demand_count.js:
186
187 ````javascript
188 #!/usr/bin/env node
189 var argv = require('yargs')
190     .demand(2)
191     .argv;
192 console.dir(argv);
193 ````
194
195 ***
196
197         $ ./demand_count.js a
198
199         Not enough non-option arguments: got 1, need at least 2
200
201         $ ./demand_count.js a b
202         { _: [ 'a', 'b' ], '$0': 'demand_count.js' }
203
204         $ ./demand_count.js a b c
205         { _: [ 'a', 'b', 'c' ], '$0': 'demand_count.js' }
206
207 EVEN MORE SHIVER ME TIMBERS!
208 ------------------
209
210 default_singles.js:
211
212 ````javascript
213 #!/usr/bin/env node
214 var argv = require('yargs')
215     .default('x', 10)
216     .default('y', 10)
217     .argv
218 ;
219 console.log(argv.x + argv.y);
220 ````
221
222 ***
223
224     $ ./default_singles.js -x 5
225     15
226
227 default_hash.js:
228
229 ````javascript
230 #!/usr/bin/env node
231 var argv = require('yargs')
232     .default({ x : 10, y : 10 })
233     .argv
234 ;
235 console.log(argv.x + argv.y);
236 ````
237
238 ***
239
240     $ ./default_hash.js -y 7
241     17
242
243 And if you really want to get all descriptive about it...
244 ---------------------------------------------------------
245
246 boolean_single.js:
247
248 ````javascript
249 #!/usr/bin/env node
250 var argv = require('yargs')
251     .boolean('v')
252     .argv
253 ;
254 console.dir(argv.v);
255 console.dir(argv._);
256 ````
257
258 ***
259
260     $ ./boolean_single.js -v "me hearties" yo ho
261     true
262     [ 'me hearties', 'yo', 'ho' ]
263
264
265 boolean_double.js:
266
267 ````javascript
268 #!/usr/bin/env node
269 var argv = require('yargs')
270     .boolean(['x','y','z'])
271     .argv
272 ;
273 console.dir([ argv.x, argv.y, argv.z ]);
274 console.dir(argv._);
275 ````
276
277 ***
278
279     $ ./boolean_double.js -x -z one two three
280     [ true, false, true ]
281     [ 'one', 'two', 'three' ]
282
283 Yargs is here to help you...
284 ---------------------------
285
286 Ye can describe parameters fer help messages and set aliases. Yargs figures
287 out how ter format a handy help string automatically.
288
289 line_count.js:
290
291 ````javascript
292 #!/usr/bin/env node
293 var argv = require('yargs')
294     .usage('Usage: $0 <command> [options]')
295     .command('count', 'Count the lines in a file')
296     .demand(1)
297     .example('$0 count -f foo.js', 'count the lines in the given file')
298     .demand('f')
299     .alias('f', 'file')
300     .nargs('f', 1)
301     .describe('f', 'Load a file')
302     .help('h')
303     .alias('h', 'help')
304     .epilog('copyright 2015')
305     .argv;
306
307 var fs = require('fs');
308 var s = fs.createReadStream(argv.file);
309
310 var lines = 0;
311 s.on('data', function (buf) {
312     lines += buf.toString().match(/\n/g).length;
313 });
314
315 s.on('end', function () {
316     console.log(lines);
317 });
318 ````
319
320 ***
321     $ node line_count.js count
322     Usage: line_count.js <command> [options]
323
324     Commands:
325       count    Count the lines in a file
326
327     Options:
328       -f, --file  Load a file        [required]
329       -h, --help  Show help           [boolean]
330
331     Examples:
332       line_count.js count -f foo.js  count the lines in the given file
333
334     copyright 2015
335
336     Missing required arguments: f
337
338     $ node line_count.js count --file line_count.js
339     26
340
341     $ node line_count.js count -f line_count.js
342     26
343
344 methods
345 =======
346
347 By itself,
348
349 ````javascript
350 require('yargs').argv
351 ````
352
353 will use the `process.argv` array to construct the `argv` object.
354
355 You can pass in the `process.argv` yourself:
356
357 ````javascript
358 require('yargs')([ '-x', '1', '-y', '2' ]).argv
359 ````
360
361 or use `.parse()` to do the same thing:
362
363 ````javascript
364 require('yargs').parse([ '-x', '1', '-y', '2' ])
365 ````
366
367 The rest of these methods below come in just before the terminating `.argv`.
368
369 <a name="alias"></a>.alias(key, alias)
370 ------------------
371
372 Set key names as equivalent such that updates to a key will propagate to aliases
373 and vice-versa.
374
375 Optionally `.alias()` can take an object that maps keys to aliases.
376 Each key of this object should be the canonical version of the option, and each
377 value should be a string or an array of strings.
378
379 .argv
380 -----
381
382 Get the arguments as a plain old object.
383
384 Arguments without a corresponding flag show up in the `argv._` array.
385
386 The script name or node command is available at `argv.$0` similarly to how `$0`
387 works in bash or perl.
388
389 If `yargs` is executed in an environment that embeds node and there's no script name (e.g.
390 [Electron](http://electron.atom.io/) or [nw.js](http://nwjs.io/)), it will ignore the first parameter since it
391 expects it to be the script name. In order to override this behavior, use `.parse(process.argv.slice(1))`
392 instead of `.argv` and the first parameter won't be ignored.
393
394 <a name="array"></a>.array(key)
395 ----------
396
397 Tell the parser to interpret `key` as an array. If `.array('foo')` is set,
398 `--foo foo bar` will be parsed as `['foo', 'bar']` rather than as `'foo'`.
399
400 <a name="boolean"></a>.boolean(key)
401 -------------
402
403 Interpret `key` as a boolean. If a non-flag option follows `key` in
404 `process.argv`, that string won't get set as the value of `key`.
405
406 `key` will default to `false`, unless a `default(key, undefined)` is
407 explicitly set.
408
409 If `key` is an array, interpret all the elements as booleans.
410
411 .check(fn)
412 ----------
413
414 Check that certain conditions are met in the provided arguments.
415
416 `fn` is called with two arguments, the parsed `argv` hash and an array of options and their aliases.
417
418 If `fn` throws or returns a non-truthy value, show the thrown error, usage information, and
419 exit.
420
421 <a name="choices"></a>.choices(key, choices)
422 ----------------------
423
424 Limit valid values for `key` to a predefined set of `choices`, given as an array
425 or as an individual value.
426
427 ```js
428 var argv = require('yargs')
429   .alias('i', 'ingredient')
430   .describe('i', 'choose your sandwich ingredients')
431   .choices('i', ['peanut-butter', 'jelly', 'banana', 'pickles'])
432   .help('help')
433   .argv
434 ```
435
436 If this method is called multiple times, all enumerated values will be merged
437 together. Choices are generally strings or numbers, and value matching is
438 case-sensitive.
439
440 Optionally `.choices()` can take an object that maps multiple keys to their
441 choices.
442
443 Choices can also be specified as `choices` in the object given to `option()`.
444
445 ```js
446 var argv = require('yargs')
447   .option('size', {
448     alias: 's',
449     describe: 'choose a size',
450     choices: ['xs', 's', 'm', 'l', 'xl']
451   })
452   .argv
453 ```
454
455 .command(cmd, desc, [fn])
456 -------------------
457
458 Document the commands exposed by your application.
459
460 Use `desc` to provide a description for each command your application accepts (the
461 values stored in `argv._`).  Set `desc` to `false` to create a hidden command.
462 Hidden commands don't show up in the help output and aren't available for
463 completion.
464
465 Optionally, you can provide a handler `fn` which will be executed when
466 a given command is provided. The handler will be called with `yargs` and
467 `argv` as arguments.
468
469 `yargs` is a blank instance of yargs, which can be used to compose a nested
470 hierarchy of options handlers.
471
472 `argv` represents the arguments parsed prior to the
473 command being executed (those described in the outer yargs instance).
474
475 Here's an example of top-level and nested commands in action:
476
477 ```js
478 var argv = require('yargs')
479   .usage('npm <command>')
480   .command('install', 'tis a mighty fine package to install')
481   .command('publish', 'shiver me timbers, should you be sharing all that', function (yargs, argv) {
482     argv = yargs.option('f', {
483       alias: 'force',
484       description: 'yar, it usually be a bad idea'
485     })
486     .help('help')
487     .argv
488   })
489   .help('help')
490   .argv;
491 ```
492
493 .completion(cmd, [description], [fn]);
494 -------------
495
496 Enable bash-completion shortcuts for commands and options.
497
498 `cmd`: When present in `argv._`, will result in the `.bashrc` completion script
499 being outputted. To enable bash completions, concat the generated script to your
500 `.bashrc` or `.bash_profile`.
501
502 `description`: Provide a description in your usage instructions for the command
503 that generates bash completion scripts.
504
505 `fn`: Rather than relying on yargs' default completion functionality, which
506 shiver me timbers is pretty awesome, you can provide your own completion
507 method.
508
509 ```js
510 var argv = require('yargs')
511   .completion('completion', function(current, argv) {
512     // 'current' is the current command being completed.
513     // 'argv' is the parsed arguments so far.
514     // simply return an array of completions.
515     return [
516       'foo',
517       'bar'
518     ];
519   })
520   .argv;
521 ```
522
523 You can also provide asynchronous completions.
524
525 ```js
526 var argv = require('yargs')
527   .completion('completion', function(current, argv, done) {
528     setTimeout(function() {
529       done([
530         'apple',
531         'banana'
532       ]);
533     }, 500);
534   })
535   .argv;
536 ```
537
538 But wait, there's more! You can return an asynchronous promise.
539
540 ```js
541 var argv = require('yargs')
542   .completion('completion', function(current, argv, done) {
543     return new Promise(function (resolve, reject) {
544       setTimeout(function () {
545         resolve(['apple', 'banana'])
546       }, 10)
547     })
548   })
549   .argv;
550 ```
551
552 <a name="config"></a>.config(key, [description], [parseFn])
553 ------------
554
555 Tells the parser that if the option specified by `key` is passed in, it
556 should be interpreted as a path to a JSON config file. The file is loaded
557 and parsed, and its properties are set as arguments.
558
559 An optional `description` can be provided to customize the config (`key`) option
560 in the usage string.
561
562 An optional `parseFn` can be used to provide a custom parser. The parsing
563 function must be synchronous, and should return an object containing
564 key value pairs or an error.
565
566 ```js
567 var argv = require('yargs')
568   .config('settings', function (configPath) {
569     return JSON.parse(fs.readFileSync(configPath, 'utf-8'))
570   })
571   .argv
572 ```
573
574 <a name="count"></a>.count(key)
575 ------------
576
577 Interpret `key` as a boolean flag, but set its parsed value to the number of
578 flag occurrences rather than `true` or `false`. Default value is thus `0`.
579
580 <a name="default"></a>.default(key, value, [description])
581 --------------------
582
583 Set `argv[key]` to `value` if no option was specified in `process.argv`.
584
585 Optionally `.default()` can take an object that maps keys to default values.
586
587 But wait, there's more! The default value can be a `function` which returns
588 a value. The name of the function will be used in the usage string:
589
590 ```js
591 var argv = require('yargs')
592   .default('random', function randomValue() {
593     return Math.random() * 256;
594   }).argv;
595 ```
596
597 Optionally, `description` can also be provided and will take precedence over
598 displaying the value in the usage instructions:
599
600 ```js
601 .default('timeout', 60000, '(one-minute)')
602 ```
603
604 <a name="demand"></a>.demand(key, [msg | boolean])
605 ------------------------------
606 .demand(count, [max], [msg])
607 ------------------------------
608
609 If `key` is a string, show the usage information and exit if `key` wasn't
610 specified in `process.argv`.
611
612 If `key` is a number, demand at least as many non-option arguments, which show
613 up in `argv._`. A second number can also optionally be provided, which indicates
614 the maximum number of non-option arguments.
615
616 If `key` is an array, demand each element.
617
618 If a `msg` string is given, it will be printed when the argument is missing,
619 instead of the standard error message. This is especially helpful for the non-option arguments in `argv._`.
620
621 If a `boolean` value is given, it controls whether the option is demanded;
622 this is useful when using `.options()` to specify command line parameters.
623
624 <a name="describe"></a>.describe(key, desc)
625 --------------------
626
627 Describe a `key` for the generated usage information.
628
629 Optionally `.describe()` can take an object that maps keys to descriptions.
630
631 .detectLocale(boolean)
632 -----------
633
634 Should yargs attempt to detect the os' locale? Defaults to `true`.
635
636 .env([prefix])
637 --------------
638
639 Tell yargs to parse environment variables matching the given prefix and apply
640 them to argv as though they were command line arguments.
641
642 If this method is called with no argument or with an empty string or with `true`,
643 then all env vars will be applied to argv.
644
645 Program arguments are defined in this order of precedence:
646
647 1. Command line args
648 2. Config file
649 3. Env var
650 4. Configured defaults
651
652 ```js
653 var argv = require('yargs')
654   .env('MY_PROGRAM')
655   .option('f', {
656     alias: 'fruit-thing',
657     default: 'apple'
658   })
659   .argv
660 console.log(argv)
661 ```
662
663 ```
664 $ node fruity.js
665 { _: [],
666   f: 'apple',
667   'fruit-thing': 'apple',
668   fruitThing: 'apple',
669   '$0': 'fruity.js' }
670 ```
671
672 ```
673 $ MY_PROGRAM_FRUIT_THING=banana node fruity.js
674 { _: [],
675   fruitThing: 'banana',
676   f: 'banana',
677   'fruit-thing': 'banana',
678   '$0': 'fruity.js' }
679 ```
680
681 ```
682 $ MY_PROGRAM_FRUIT_THING=banana node fruity.js -f cat
683 { _: [],
684   f: 'cat',
685   'fruit-thing': 'cat',
686   fruitThing: 'cat',
687   '$0': 'fruity.js' }
688 ```
689
690 Env var parsing is disabled by default, but you can also explicitly disable it
691 by calling `.env(false)`, e.g. if you need to undo previous configuration.
692
693 .epilog(str)
694 ------------
695 .epilogue(str)
696 --------------
697
698 A message to print at the end of the usage instructions, e.g.
699
700 ```js
701 var argv = require('yargs')
702   .epilogue('for more information, find our manual at http://example.com');
703 ```
704
705 .example(cmd, desc)
706 -------------------
707
708 Give some example invocations of your program. Inside `cmd`, the string
709 `$0` will get interpolated to the current script name or node command for the
710 present script similar to how `$0` works in bash or perl.
711 Examples will be printed out as part of the help message.
712
713 .exitProcess(enable)
714 ----------------------------------
715
716 By default, yargs exits the process when the user passes a help flag, uses the
717 `.version` functionality, or when validation fails. Calling
718 `.exitProcess(false)` disables this behavior, enabling further actions after
719 yargs have been validated.
720
721 .fail(fn)
722 ---------
723
724 Method to execute when a failure occurs, rather than printing the failure message.
725
726 `fn` is called with the failure message that would have been printed.
727
728 <a name="group"></a>.group(key(s), groupName)
729 --------------------
730
731 Given a key, or an array of keys, places options under an alternative heading
732 when displaying usage instructions, e.g.,
733
734 ```js
735 var yargs = require('yargs')(['--help'])
736   .help('help')
737   .group('batman', 'Heroes:')
738   .describe('batman', "world's greatest detective")
739   .wrap(null)
740   .argv
741 ```
742 ***
743     Heroes:
744       --batman  world's greatest detective
745
746     Options:
747       --help  Show help  [boolean]
748
749 .help([option, [description]])
750 ------------------------------
751
752 Add an option (e.g. `--help`) that displays the usage string and exits the
753 process. If present, the `description` parameter customizes the description of
754 the help option in the usage string.
755
756 If invoked without parameters, `.help()` returns the generated usage string.
757
758 Example:
759
760 ```js
761 var yargs = require("yargs")
762   .usage("$0 -operand1 number -operand2 number -operation [add|subtract]");
763 console.log(yargs.help());
764 ```
765
766 Later on, `argv` can be retrieved with `yargs.argv`.
767
768 .implies(x, y)
769 --------------
770
771 Given the key `x` is set, it is required that the key `y` is set.
772
773 Optionally `.implies()` can accept an object specifying multiple implications.
774
775 .locale()
776 ---------
777
778 Return the locale that yargs is currently using.
779
780 By default, yargs will auto-detect the operating system's locale so that
781 yargs-generated help content will display in the user's language.
782
783 To override this behavior with a static locale, pass the desired locale as a
784 string to this method (see below).
785
786 .locale(locale)
787 ---------------
788
789 Override the auto-detected locale from the user's operating system with a static
790 locale. Note that the OS locale can be modified by setting/exporting the `LC_ALL`
791 environment variable.
792
793 ```js
794 var argv = require('yargs')
795   .usage('./$0 - follow ye instructions true')
796   .option('option', {
797     alias: 'o',
798     describe: "'tis a mighty fine option",
799     demand: true
800   })
801   .command('run', "Arrr, ya best be knowin' what yer doin'")
802   .example('$0 run foo', "shiver me timbers, here's an example for ye")
803   .help('help')
804   .wrap(70)
805   .locale('pirate')
806   .argv
807 ```
808
809 ***
810
811 ```shell
812 ./test.js - follow ye instructions true
813
814 Choose yer command:
815   run  Arrr, ya best be knowin' what yer doin'
816
817 Options for me hearties!
818   --option, -o  'tis a mighty fine option               [requi-yar-ed]
819   --help        Parlay this here code of conduct             [boolean]
820
821 Ex. marks the spot:
822   test.js run foo  shiver me timbers, here's an example for ye
823
824 Ye be havin' to set the followin' argument land lubber: option
825 ```
826
827 Locales currently supported:
828
829 * **de:** German.
830 * **en:** American English.
831 * **es:** Spanish.
832 * **fr:** French.
833 * **id:** Indonesian.
834 * **ja:** Japanese.
835 * **ko:** Korean.
836 * **nb:** Norwegian BokmÃ¥l.
837 * **pirate:** American Pirate.
838 * **pt:** Portuguese.
839 * **pt_BR:** Brazilian Portuguese.
840 * **tr:** Turkish.
841 * **zh:** Chinese.
842
843 To submit a new translation for yargs:
844
845 1. use `./locales/en.json` as a starting point.
846 2. submit a pull request with the new locale file.
847
848 *The [Microsoft Terminology Search](http://www.microsoft.com/Language/en-US/Search.aspx) can be useful for finding the correct terminology in your locale.*
849
850 <a name="nargs"></a>.nargs(key, count)
851 -----------
852
853 The number of arguments that should be consumed after a key. This can be a
854 useful hint to prevent parsing ambiguity. For example:
855
856 ```js
857 var argv = require('yargs')
858   .nargs('token', 1)
859   .parse(['--token', '-my-token']);
860 ```
861
862 parses as:
863
864 `{ _: [], token: '-my-token', '$0': 'node test' }`
865
866 Optionally `.nargs()` can take an object of `key`/`narg` pairs.
867
868 .option(key, opt)
869 -----------------
870 .options(key, opt)
871 ------------------
872
873 Instead of chaining together `.alias().demand().default().describe().string()`, you can specify
874 keys in `opt` for each of the chainable methods.
875
876 For example:
877
878 ````javascript
879 var argv = require('yargs')
880     .option('f', {
881         alias: 'file',
882         demand: true,
883         default: '/etc/passwd',
884         describe: 'x marks the spot',
885         type: 'string'
886     })
887     .argv
888 ;
889 ````
890
891 is the same as
892
893 ````javascript
894 var argv = require('yargs')
895     .alias('f', 'file')
896     .demand('f')
897     .default('f', '/etc/passwd')
898     .describe('f', 'x marks the spot')
899     .string('f')
900     .argv
901 ;
902 ````
903
904 Optionally `.options()` can take an object that maps keys to `opt` parameters.
905
906 ````javascript
907 var argv = require('yargs')
908     .options({
909       'f': {
910         alias: 'file',
911         demand: true,
912         default: '/etc/passwd',
913         describe: 'x marks the spot',
914         type: 'string'
915       }
916     })
917     .argv
918 ;
919 ````
920
921 Valid `opt` keys include:
922
923 - `alias`: string or array of strings, alias(es) for the canonical option key, see [`alias()`](#alias)
924 - `array`: boolean, interpret option as an array, see [`array()`](#array)
925 - `boolean`: boolean, interpret option as a boolean flag, see [`boolean()`](#boolean)
926 - `choices`: value or array of values, limit valid option arguments to a predefined set, see [`choices()`](#choices)
927 - `config`: boolean, interpret option as a path to a JSON config file, see [`config()`](#config)
928 - `configParser`: function, provide a custom config parsing function, see [`config()`](#config)
929 - `count`: boolean, interpret option as a count of boolean flags, see [`count()`](#count)
930 - `default`: value, set a default value for the option, see [`default()`](#default)
931 - `defaultDescription`: string, use this description for the default value in help content, see [`default()`](#default)
932 - `demand`/`require`/`required`: boolean or string, demand the option be given, with optional error message, see [`demand()`](#demand)
933 - `desc`/`describe`/`description`: string, the option description for help content, see [`describe()`](#describe)
934 - `group`: string, when displaying usage instructions place the option under an alternative group heading, see [`group()`](#group)
935 - `nargs`: number, specify how many arguments should be consumed for the option, see [`nargs()`](#nargs)
936 - `requiresArg`: boolean, require the option be specified with a value, see [`requiresArg()`](#requiresArg)
937 - `string`: boolean, interpret option as a string, see [`string()`](#string)
938 - `type`: one of the following strings
939     - `'array'`: synonymous for `array: true`, see [`array()`](#array)
940     - `'boolean'`: synonymous for `boolean: true`, see [`boolean()`](#boolean)
941     - `'count'`: synonymous for `count: true`, see [`count()`](#count)
942     - `'string'`: synonymous for `string: true`, see [`string()`](#string)
943
944 .parse(args)
945 ------------
946
947 Parse `args` instead of `process.argv`. Returns the `argv` object.
948
949 `args` may either be a pre-processed argv array, or a raw argument string.
950
951 .require(key, [msg | boolean])
952 ------------------------------
953 .required(key, [msg | boolean])
954 ------------------------------
955
956 An alias for [`demand()`](#demand). See docs there.
957
958 <a name="requiresArg"></a>.requiresArg(key)
959 -----------------
960
961 Specifies either a single option key (string), or an array of options that
962 must be followed by option values. If any option value is missing, show the
963 usage information and exit.
964
965 The default behavior is to set the value of any key not followed by an
966 option value to `true`.
967
968 .reset()
969 --------
970
971 Reset the argument object built up so far. This is useful for
972 creating nested command line interfaces.
973
974 ```js
975 var yargs = require('yargs')
976   .usage('$0 command')
977   .command('hello', 'hello command')
978   .command('world', 'world command')
979   .demand(1, 'must provide a valid command'),
980   argv = yargs.argv,
981   command = argv._[0];
982
983 if (command === 'hello') {
984   yargs.reset()
985     .usage('$0 hello')
986     .help('h')
987     .example('$0 hello', 'print the hello message!')
988     .argv
989
990   console.log('hello!');
991 } else if (command === 'world'){
992   yargs.reset()
993     .usage('$0 world')
994     .help('h')
995     .example('$0 world', 'print the world message!')
996     .argv
997
998   console.log('world!');
999 } else {
1000   yargs.showHelp();
1001 }
1002 ```
1003
1004 .showCompletionScript()
1005 ----------------------
1006
1007 Generate a bash completion script. Users of your application can install this
1008 script in their `.bashrc`, and yargs will provide completion shortcuts for
1009 commands and options.
1010
1011 .showHelp(consoleLevel='error')
1012 ---------------------------
1013
1014 Print the usage data using the [`console`](https://nodejs.org/api/console.html) function `consoleLevel` for printing.
1015
1016 Example:
1017
1018 ```js
1019 var yargs = require("yargs")
1020   .usage("$0 -operand1 number -operand2 number -operation [add|subtract]");
1021 yargs.showHelp(); //prints to stderr using console.error()
1022 ```
1023
1024 Or, to print the usage data to `stdout` instead, you can specify the use of `console.log`:
1025
1026 ```js
1027 yargs.showHelp("log"); //prints to stdout using console.log()
1028 ```
1029
1030 Later on, `argv` can be retrieved with `yargs.argv`.
1031
1032 .showHelpOnFail(enable, [message])
1033 ----------------------------------
1034
1035 By default, yargs outputs a usage string if any error is detected. Use the
1036 `.showHelpOnFail()` method to customize this behavior. If `enable` is `false`,
1037 the usage string is not output. If the `message` parameter is present, this
1038 message is output after the error message.
1039
1040 line_count.js:
1041
1042 ````javascript
1043 #!/usr/bin/env node
1044 var argv = require('yargs')
1045     .usage('Count the lines in a file.\nUsage: $0 -f <file>')
1046     .demand('f')
1047     .alias('f', 'file')
1048     .describe('f', 'Load a file')
1049     .string('f')
1050     .showHelpOnFail(false, 'Specify --help for available options')
1051     .help('help')
1052     .argv;
1053
1054 // etc.
1055 ````
1056
1057 ***
1058
1059 ```
1060 $ node line_count.js
1061 Missing argument value: f
1062
1063 Specify --help for available options
1064 ```
1065
1066 .strict()
1067 ---------
1068
1069 Any command-line argument given that is not demanded, or does not have a
1070 corresponding description, will be reported as an error.
1071
1072 <a name="string"></a>.string(key)
1073 ------------
1074
1075 Tell the parser logic not to interpret `key` as a number or boolean.
1076 This can be useful if you need to preserve leading zeros in an input.
1077
1078 If `key` is an array, interpret all the elements as strings.
1079
1080 `.string('_')` will result in non-hyphenated arguments being interpreted as strings,
1081 regardless of whether they resemble numbers.
1082
1083 .updateLocale(obj)
1084 ------------------
1085 .updateStrings(obj)
1086 ------------------
1087
1088 Override the default strings used by yargs with the key/value
1089 pairs provided in `obj`:
1090
1091 ```js
1092 var argv = require('yargs')
1093   .command('run', 'the run command')
1094   .help('help')
1095   .updateStrings({
1096     'Commands:': 'My Commands -->\n'
1097   })
1098   .wrap(null)
1099   .argv
1100 ```
1101
1102 ***
1103
1104 ```shell
1105 My Commands -->
1106
1107   run  the run command
1108
1109 Options:
1110   --help  Show help  [boolean]
1111 ```
1112
1113 If you explicitly specify a `locale()`, you should do so *before* calling
1114 `updateStrings()`.
1115
1116 .usage(message, [opts])
1117 ---------------------
1118
1119 Set a usage message to show which commands to use. Inside `message`, the string
1120 `$0` will get interpolated to the current script name or node command for the
1121 present script similar to how `$0` works in bash or perl.
1122
1123 `opts` is optional and acts like calling `.options(opts)`.
1124
1125 .version(version, [option], [description])
1126 ----------------------------------------
1127
1128 Add an option (e.g. `--version`) that displays the version number (given by the
1129 `version` parameter) and exits the process. If present, the `description`
1130 parameter customizes the description of the version option in the usage string.
1131
1132 You can provide a `function` for version, rather than a string.
1133 This is useful if you want to use the version from your package.json:
1134
1135 ```js
1136 var argv = require('yargs')
1137   .version(function() {
1138     return require('../package').version;
1139   })
1140   .argv;
1141 ```
1142
1143 .wrap(columns)
1144 --------------
1145
1146 Format usage output to wrap at `columns` many columns.
1147
1148 By default wrap will be set to `Math.min(80, windowWidth)`. Use `.wrap(null)` to
1149 specify no column limit (no right-align). Use `.wrap(yargs.terminalWidth())` to
1150 maximize the width of yargs' usage instructions.
1151
1152 parsing tricks
1153 ==============
1154
1155 stop parsing
1156 ------------
1157
1158 Use `--` to stop parsing flags and stuff the remainder into `argv._`.
1159
1160     $ node examples/reflect.js -a 1 -b 2 -- -c 3 -d 4
1161     { _: [ '-c', '3', '-d', '4' ],
1162       a: 1,
1163       b: 2,
1164       '$0': 'examples/reflect.js' }
1165
1166 negate fields
1167 -------------
1168
1169 If you want to explicitly set a field to false instead of just leaving it
1170 undefined or to override a default you can do `--no-key`.
1171
1172     $ node examples/reflect.js -a --no-b
1173     { _: [], a: true, b: false, '$0': 'examples/reflect.js' }
1174
1175 numbers
1176 -------
1177
1178 Every argument that looks like a number (`!isNaN(Number(arg))`) is converted to
1179 one. This way you can just `net.createConnection(argv.port)` and you can add
1180 numbers out of `argv` with `+` without having that mean concatenation,
1181 which is super frustrating.
1182
1183 duplicates
1184 ----------
1185
1186 If you specify a flag multiple times it will get turned into an array containing
1187 all the values in order.
1188
1189     $ node examples/reflect.js -x 5 -x 8 -x 0
1190     { _: [], x: [ 5, 8, 0 ], '$0': 'examples/reflect.js' }
1191
1192 dot notation
1193 ------------
1194
1195 When you use dots (`.`s) in argument names, an implicit object path is assumed.
1196 This lets you organize arguments into nested objects.
1197
1198     $ node examples/reflect.js --foo.bar.baz=33 --foo.quux=5
1199     { _: [],
1200       foo: { bar: { baz: 33 }, quux: 5 },
1201       '$0': 'examples/reflect.js' }
1202
1203 short numbers
1204 -------------
1205
1206 Short numeric `-n5` style arguments work too:
1207
1208     $ node examples/reflect.js -n123 -m456
1209     { _: [], n: 123, m: 456, '$0': 'examples/reflect.js' }
1210
1211 installation
1212 ============
1213
1214 With [npm](https://github.com/npm/npm), just do:
1215
1216     npm install yargs
1217
1218 or clone this project on github:
1219
1220     git clone http://github.com/bcoe/yargs.git
1221
1222 To run the tests with npm, just do:
1223
1224     npm test
1225
1226 inspired by
1227 ===========
1228
1229 This module is loosely inspired by Perl's
1230 [Getopt::Casual](http://search.cpan.org/~photo/Getopt-Casual-0.13.1/Casual.pm).
1231
1232
1233
1234 [travis-url]: https://travis-ci.org/bcoe/yargs
1235 [travis-image]: https://img.shields.io/travis/bcoe/yargs.svg
1236 [gemnasium-url]: https://gemnasium.com/bcoe/yargs
1237 [gemnasium-image]: https://img.shields.io/gemnasium/bcoe/yargs.svg
1238 [coveralls-url]: https://coveralls.io/github/bcoe/yargs
1239 [coveralls-image]: https://img.shields.io/coveralls/bcoe/yargs.svg
1240 [npm-url]: https://www.npmjs.com/package/yargs
1241 [npm-image]: https://img.shields.io/npm/v/yargs.svg
1242 [windows-url]: https://ci.appveyor.com/project/bcoe/yargs
1243 [windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs/master.svg?label=Windows%20Tests