(val, invalidValueMessage, valueSource)
| 681 | |
| 682 | // handler for cli and env supplied values |
| 683 | const handleOptionValue = (val, invalidValueMessage, valueSource) => { |
| 684 | // val is null for optional option used without an optional-argument. |
| 685 | // val is undefined for boolean and negated option. |
| 686 | if (val == null && option.presetArg !== undefined) { |
| 687 | val = option.presetArg; |
| 688 | } |
| 689 | |
| 690 | // custom processing |
| 691 | const oldValue = this.getOptionValue(name); |
| 692 | if (val !== null && option.parseArg) { |
| 693 | val = this._callParseArg(option, val, oldValue, invalidValueMessage); |
| 694 | } else if (val !== null && option.variadic) { |
| 695 | val = option._collectValue(val, oldValue); |
| 696 | } |
| 697 | |
| 698 | // Fill-in appropriate missing values. Long winded but easy to follow. |
| 699 | if (val == null) { |
| 700 | if (option.negate) { |
| 701 | val = false; |
| 702 | } else if (option.isBoolean() || option.optional) { |
| 703 | val = true; |
| 704 | } else { |
| 705 | val = ''; // not normal, parseArg might have failed or be a mock function for testing |
| 706 | } |
| 707 | } |
| 708 | this.setOptionValueWithSource(name, val, valueSource); |
| 709 | }; |
| 710 | |
| 711 | this.on('option:' + oname, (val) => { |
| 712 | const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`; |
nothing calls this directly
no test coverage detected