From d4bc30a17f431586a1769f236bf7816e7398dd28 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Thu, 5 Jan 2017 21:50:58 -0800 Subject: [PATCH] fix: address min/max validation message regression --- test/validation.js | 11 +++++++++++ yargs.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/validation.js b/test/validation.js index 14d864b5f..7b79e2f11 100644 --- a/test/validation.js +++ b/test/validation.js @@ -239,6 +239,17 @@ describe('validation tests', function () { .argv }) + // address regression in: https://github.com/yargs/yargs/pull/740 + it('custom failure message should be printed for both min and max constraints', function (done) { + yargs(['foo']) + .demand(0, 0, 'hey! give me a custom exit message') + .fail(function (msg) { + expect(msg).to.equal('hey! give me a custom exit message') + return done() + }) + .argv + }) + it('interprets min relative to command', function () { var failureMsg yargs('lint') diff --git a/yargs.js b/yargs.js index a63c94a4b..8ee528e62 100644 --- a/yargs.js +++ b/yargs.js @@ -318,7 +318,7 @@ function Yargs (processArgs, cwd, parentRequire) { } if (typeof keys === 'number') { - self.demandCommand(keys, max, msg) + self.demandCommand(keys, max, msg, msg) } else if (Array.isArray(keys)) { keys.forEach(function (key) { self.demandOption(key, msg)