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 1452f6f commit ddf5ce7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -851,6 +851,7 @@ 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 ddf5ce7

Please sign in to comment.