Skip to content

Commit 2e5ce0f

Browse files
authored
fix: address min/max validation message regression (#750)
1 parent 8de8272 commit 2e5ce0f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

test/validation.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ describe('validation tests', function () {
239239
.argv
240240
})
241241

242+
// address regression in: https://github.com/yargs/yargs/pull/740
243+
it('custom failure message should be printed for both min and max constraints', function (done) {
244+
yargs(['foo'])
245+
.demand(0, 0, 'hey! give me a custom exit message')
246+
.fail(function (msg) {
247+
expect(msg).to.equal('hey! give me a custom exit message')
248+
return done()
249+
})
250+
.argv
251+
})
252+
242253
it('interprets min relative to command', function () {
243254
var failureMsg
244255
yargs('lint')

yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function Yargs (processArgs, cwd, parentRequire) {
318318
}
319319

320320
if (typeof keys === 'number') {
321-
self.demandCommand(keys, max, msg)
321+
self.demandCommand(keys, max, msg, msg)
322322
} else if (Array.isArray(keys)) {
323323
keys.forEach(function (key) {
324324
self.demandOption(key, msg)

0 commit comments

Comments
 (0)