Skip to content

Commit

Permalink
Fail when using same command and alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfranzoia committed Jan 25, 2016
1 parent 1452f6f commit 1932f4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -851,6 +851,9 @@ Command.prototype.description = function(str) {

Command.prototype.alias = function(alias) {
if (0 == arguments.length) return this._alias;
if (alias === this._name) {
throw new Error('Command alias can\'t be the same as its name');
}
this._alias = alias;
return this;
};
Expand Down
14 changes: 14 additions & 0 deletions test/test.command.failOnSameAlias.js
@@ -0,0 +1,14 @@
var program = require('../')
, should = require('should');

var error;

try {
program
.command('fail')
.alias('fail');
} catch (e) {
error = e;
}

error.should.deepEqual(new Error('Command alias can\'t be the same as its name'));

0 comments on commit 1932f4b

Please sign in to comment.