@@ -632,57 +632,29 @@ Expecting one of '${allowedValues.join("', '")}'`);
632
632
}
633
633
634
634
/**
635
- * Define option with `flags`, `description` and optional
636
- * coercion `fn`.
635
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
637
636
*
638
- * The `flags` string contains the short and/or long flags,
639
- * separated by comma, a pipe or space. The following are all valid
640
- * all will output this way when `--help` is used.
637
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
638
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
641
639
*
642
- * "-p, --pepper"
643
- * "-p|--pepper"
644
- * "-p --pepper"
640
+ * See the README for more details, and see also addOption() and requiredOption().
645
641
*
646
642
* @example
647
- * // simple boolean defaulting to undefined
648
- * program.option('-p, --pepper', 'add pepper');
649
- *
650
- * program.pepper
651
- * // => undefined
652
- *
653
- * --pepper
654
- * program.pepper
655
- * // => true
656
- *
657
- * // simple boolean defaulting to true (unless non-negated option is also defined)
658
- * program.option('-C, --no-cheese', 'remove cheese');
659
- *
660
- * program.cheese
661
- * // => true
662
- *
663
- * --no-cheese
664
- * program.cheese
665
- * // => false
666
- *
667
- * // required argument
668
- * program.option('-C, --chdir <path>', 'change the working directory');
669
- *
670
- * --chdir /tmp
671
- * program.chdir
672
- * // => "/tmp"
673
- *
674
- * // optional argument
675
- * program.option('-c, --cheese [type]', 'add cheese [marble]');
643
+ * program
644
+ * .option('-p, --pepper', 'add pepper')
645
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
646
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
647
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
676
648
*
677
649
* @param {string } flags
678
650
* @param {string } [description]
679
- * @param {Function|* } [fn ] - custom option processing function or default value
651
+ * @param {Function|* } [parseArg ] - custom option processing function or default value
680
652
* @param {* } [defaultValue]
681
653
* @return {Command } `this` command for chaining
682
654
*/
683
655
684
- option ( flags , description , fn , defaultValue ) {
685
- return this . _optionEx ( { } , flags , description , fn , defaultValue ) ;
656
+ option ( flags , description , parseArg , defaultValue ) {
657
+ return this . _optionEx ( { } , flags , description , parseArg , defaultValue ) ;
686
658
}
687
659
688
660
/**
@@ -693,13 +665,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
693
665
*
694
666
* @param {string } flags
695
667
* @param {string } [description]
696
- * @param {Function|* } [fn ] - custom option processing function or default value
668
+ * @param {Function|* } [parseArg ] - custom option processing function or default value
697
669
* @param {* } [defaultValue]
698
670
* @return {Command } `this` command for chaining
699
671
*/
700
672
701
- requiredOption ( flags , description , fn , defaultValue ) {
702
- return this . _optionEx ( { mandatory : true } , flags , description , fn , defaultValue ) ;
673
+ requiredOption ( flags , description , parseArg , defaultValue ) {
674
+ return this . _optionEx ( { mandatory : true } , flags , description , parseArg , defaultValue ) ;
703
675
}
704
676
705
677
/**
0 commit comments