Skip to content

Commit

Permalink
Fail when using same command and alias (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfranzoia authored and abetomo committed Aug 9, 2017
1 parent df86179 commit 2f07e29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -880,6 +880,8 @@ Command.prototype.alias = function(alias) {

if (arguments.length === 0) return command._alias;

if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');

command._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 2f07e29

Please sign in to comment.