Skip to content

Commit

Permalink
implement Command.prototype.name()
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylukasavage committed Sep 23, 2014
1 parent 6089ed4 commit bfa7a73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,20 @@ Command.prototype.usage = function(str){
return this;
};

/**
* Set / get the name for the command
*
* @param {String} name
* @return {String|Command}
* @api public
*/

Command.prototype.name = function(name){
if (0 == arguments.length) return this._name;
this._name = name;
return this;
};

/**
* Return the largest option length.
*
Expand Down
14 changes: 14 additions & 0 deletions test/test.command.name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var program = require('../')
, should = require('should');

program
.command('mycommand [options]', 'this is my command');

program.parse(['node', 'test']);

program.name.should.be.a.Function;
program.name().should.equal('test');
program.commands[0].name().should.equal('mycommand');
program.commands[1].name().should.equal('help');
program.commands[0].name('newcommand');
program.commands[0].name().should.equal('newcommand');

0 comments on commit bfa7a73

Please sign in to comment.