From ce848a699e9c48a870781c3dad10806b9254f2a2 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.options.failOnSameAlias.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/test.options.failOnSameAlias.js diff --git a/index.js b/index.js index 715c4df98..b39998b9b 100644 --- a/index.js +++ b/index.js @@ -851,6 +851,9 @@ 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.options.failOnSameAlias.js b/test/test.options.failOnSameAlias.js new file mode 100644 index 000000000..6b7527631 --- /dev/null +++ b/test/test.options.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'));