From aa9aa6eee9d07903547840409853d79d483d1298 Mon Sep 17 00:00:00 2001 From: John Gee Date: Mon, 20 Dec 2021 22:28:55 +1300 Subject: [PATCH 1/2] Throw error for wrong argument to option or requiredOption --- lib/command.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/command.js b/lib/command.js index c98712917..0b0c6a374 100644 --- a/lib/command.js +++ b/lib/command.js @@ -581,6 +581,10 @@ Expecting one of '${allowedValues.join("', '")}'`); * @api private */ _optionEx(config, flags, description, fn, defaultValue) { + if (typeof flags !== 'string') { + // Have specific error for usage error, like passing Option, to speed up fixing. + throw new Error('First argument to option() and requiredOption() must be a string'); + } const option = this.createOption(flags, description); option.makeOptionMandatory(!!config.mandatory); if (typeof fn === 'function') { From 3e9d01c4511171b5075f06849ce3f606e13406b5 Mon Sep 17 00:00:00 2001 From: John Gee Date: Mon, 20 Dec 2021 22:51:02 +1300 Subject: [PATCH 2/2] Make test and error message more specific --- lib/command.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/command.js b/lib/command.js index 0b0c6a374..738accdf8 100644 --- a/lib/command.js +++ b/lib/command.js @@ -581,9 +581,8 @@ Expecting one of '${allowedValues.join("', '")}'`); * @api private */ _optionEx(config, flags, description, fn, defaultValue) { - if (typeof flags !== 'string') { - // Have specific error for usage error, like passing Option, to speed up fixing. - throw new Error('First argument to option() and requiredOption() must be a string'); + if (typeof flags === 'object' && flags instanceof Option) { + throw new Error('To add an Option object use addOption() instead of option() or requiredOption()'); } const option = this.createOption(flags, description); option.makeOptionMandatory(!!config.mandatory);