From e636703299e6d1ca2b54d1107e3b2695ec59c197 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 | 3 +++ test/test.command.failOnSameAlias.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/test.command.failOnSameAlias.js diff --git a/index.js b/index.js index 4ca2829b6..c15228df1 100644 --- a/index.js +++ b/index.js @@ -880,7 +880,10 @@ 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'));