From ddf5ce76a8c464d80f269149234c0dbb9e3e8172 Mon Sep 17 00:00:00 2001 From: Augusto Franzoia Date: Mon, 25 Jan 2016 01:39:38 -0300 Subject: [PATCH] Fail when using same command and alias --- index.js | 1 + test/test.command.failOnSameAlias.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/test.command.failOnSameAlias.js 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'));