diff --git a/lib/option.js b/lib/option.js index 4a0bd7fac..dca229ee7 100644 --- a/lib/option.js +++ b/lib/option.js @@ -34,6 +34,7 @@ class Option { this.conflictsWith = []; this.implied = undefined; this.helpGroupHeading = undefined; // soft initialised when option added to command + this.attribName = undefined; } /** @@ -194,6 +195,19 @@ class Option { return this; } + /** + * Allow to change the attribute name of this option. + * + * @param {string} attributeName is used for a alternated attribute name + * @return {Option} + */ + + setAttributeName(attributeName) { + if (typeof attributeName === 'string') { + this.attribName = attributeName; + } + return this; + } /** * Return option name. * @@ -209,12 +223,17 @@ class Option { /** * Return option name, in a camelcase format that can be used - * as an object attribute key. + * as an object attribute key. + * This method now uses alternativly the this.attributeName when it is set otherwise + * it will still use the option name as before * * @return {string} */ attributeName() { + if (typeof this.attribName === 'string') { + return this.attribName; + } if (this.negate) { return camelcase(this.name().replace(/^no-/, '')); }