Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 51 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,68 @@ exports = module.exports = new Command();

exports.Command = Command;

/**
* Expose `Option`.
*/
class Option {
/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {String} flags
* @param {String} description
* @api public
*/

exports.Option = Option;
constructor(flags, description) {
this.flags = flags;
this.required = flags.indexOf('<') >= 0; // A value must be supplied when the option is specified.
this.optional = flags.indexOf('[') >= 0; // A value is optional when the option is specified.
this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
this.negate = flags.indexOf('-no-') !== -1;
flags = flags.split(/[ ,|]+/);
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
this.long = flags.shift();
this.description = description || '';
}

/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {String} flags
* @param {String} description
* @api public
*/
/**
* Return option name.
*
* @return {String}
* @api private
*/

function Option(flags, description) {
this.flags = flags;
this.required = flags.indexOf('<') >= 0; // A value must be supplied when the option is specified.
this.optional = flags.indexOf('[') >= 0; // A value is optional when the option is specified.
this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
this.negate = flags.indexOf('-no-') !== -1;
flags = flags.split(/[ ,|]+/);
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
this.long = flags.shift();
this.description = description || '';
}
name() {
return this.long.replace(/^--/, '');
};

/**
* Return option name.
*
* @return {String}
* @api private
*/
/**
* Return option name, in a camelcase format that can be used
* as a object attribute key.
*
* @return {String}
* @api private
*/

Option.prototype.name = function() {
return this.long.replace(/^--/, '');
};
attributeName() {
return camelcase(this.name().replace(/^no-/, ''));
};

/**
* Return option name, in a camelcase format that can be used
* as a object attribute key.
*
* @return {String}
* @api private
*/
/**
* Check if `arg` matches the short or long flag.
*
* @param {String} arg
* @return {Boolean}
* @api private
*/

Option.prototype.attributeName = function() {
return camelcase(this.name().replace(/^no-/, ''));
};
is(arg) {
return this.short === arg || this.long === arg;
};
}

/**
* Check if `arg` matches the short or long flag.
*
* @param {String} arg
* @return {Boolean}
* @api private
* Expose `Option`.
*/

Option.prototype.is = function(arg) {
return this.short === arg || this.long === arg;
};
exports.Option = Option;

/**
* CommanderError class
Expand Down