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 Aug 8, 2017
1 parent 5c74431 commit 2e329a3
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 2e329a3

Please sign in to comment.