From 24ca282d4db9b237d9fee3d97c57fdbb915c24a5 Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 21 Dec 2021 16:41:46 +1300 Subject: [PATCH] Throw error for Option to option() or requiredOption() (#1655) * Throw error for wrong argument to option or requiredOption * Make test and error message more specific --- lib/command.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/command.js b/lib/command.js index d0a4af620..d03e060f8 100644 --- a/lib/command.js +++ b/lib/command.js @@ -580,6 +580,9 @@ Expecting one of '${allowedValues.join("', '")}'`); * @api private */ _optionEx(config, flags, description, fn, defaultValue) { + 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); if (typeof fn === 'function') {