Skip to content
Myr

add attributeName() method to Option objects

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Mostly because it should be possible to query what will be the `program` attribute name for a given option. As it was, the `camelcase` function was internal to the Option class and not accessible from the outside.

authored by Yanick Champoux · committed by Roman Vanesyan · parent d359b75 · Browse files · 1 file+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−2 removed

  • other:+14 added−2 removed

1 file+14 added−2 removed

modified:index.js+14 added-2 removed
58 unmodified lines
59 .replace('no-', '');60};6162/**63 * Return option name, in a camelcase format that can be used64 * as a object attribute key.65 *66 * @return {String}67 * @api private68 */6970Option.prototype.attributeName = function() {71 return camelcase( this.name() );72};7374/**75 * Check if `arg` matches the short or long flag.76 *77 * @param {String} arg78 * @return {Boolean}
294 unmodified lines
373Command.prototype.option = function(flags, description, fn, defaultValue) {374 var self = this375 , option = new Option(flags, description)376 , oname = option.name()365 , name = camelcase(oname);377 , name = option.attributeName();378379 // default as 3rd arg380 if (typeof fn != 'function') {381 if (fn instanceof RegExp) {
390 unmodified lines
772 var result = {}773 , len = this.options.length;774775 for (var i = 0 ; i < len; i++) {764 var key = camelcase(this.options[i].name());776 var key = this.options[i].attributeName();777 result[key] = key === 'version' ? this._version : this[key];778 }779 return result;780};
378 unmodified lines