From 2e329a3a03ec437061a8403b2a0b5474e3e00169 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 | 2 ++ test/test.command.failOnSameAlias.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/test.command.failOnSameAlias.js diff --git a/index.js b/index.js index 4ca2829b6..675575dc4 100644 --- a/index.js +++ b/index.js @@ -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; }; 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'));