From 4dec08afbc0c96e454dd532ed9cfa16a4a1ddd51 Mon Sep 17 00:00:00 2001 From: n loewen Date: Sat, 2 Sep 2023 16:40:51 -0400 Subject: [PATCH] Fix: Correctly check synonyms when checking if an option is provided by the user --- opter.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/opter.js b/opter.js index 5591aac..bc83b21 100644 --- a/opter.js +++ b/opter.js @@ -51,8 +51,8 @@ module.exports = class Opts { const name = stripDashes(nameWithDashes); if (name in this.opts) return true; if (name in this.synonyms) { - let syns = this.synonyms[name]; - let hits = syns.filter(s => s in this.opts ).length; + const syns = this.synonyms[name]; + const hits = syns.filter(s => s in this.opts ).length; if (hits > 0) { return true; } } throw new Error(errorMessage || defaultErrorMessages.missingRequiredOption(nameWithDashes)); @@ -94,7 +94,11 @@ module.exports = class Opts { contains(nameWithDashes) { const name = stripDashes(nameWithDashes); if (name in this.opts) return true; - if (name in this.synonyms) return true; // FIXME + if (name in this.synonyms) { + const syns = this.synonyms[name]; + const hits = syns.filter(s => s in this.opts ).length; + if (hits > 0) { return true; } + } return false; } }