diff --git a/index.js b/index.js index 715c4df98..0c8aeeecc 100644 --- a/index.js +++ b/index.js @@ -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; }; diff --git a/test/test.command.failOnSameAlias.js b/test/test.command.failOnSameAlias.js new file mode 100644 index 000000000..6b7527631 --- /dev/null +++ b/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'));