From 07a5554c480ff3aa43cdc37b1d4ecbaf2687c779 Mon Sep 17 00:00:00 2001 From: Cameron Hunter Date: Mon, 29 Jul 2019 15:55:13 -0700 Subject: [PATCH] feat: adds support for multiple epilog messages (#1384) --- lib/usage.js | 14 +++++++------- test/usage.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/usage.js b/lib/usage.js index 98d1508b0..fed6d9f69 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -122,9 +122,9 @@ module.exports = function usage (yargs, y18n) { } self.getDescriptions = () => descriptions - let epilog + let epilogs = [] self.epilog = (msg) => { - epilog = msg + epilogs.push(msg) } let wrapSet = false @@ -345,8 +345,8 @@ module.exports = function usage (yargs, y18n) { } // the usage string. - if (epilog) { - const e = epilog.replace(/\$0/g, base$0) + if (epilogs.length > 0) { + const e = epilogs.map(epilog => epilog.replace(/\$0/g, base$0)).join('\n') ui.div(`${e}\n`) } @@ -505,7 +505,7 @@ module.exports = function usage (yargs, y18n) { failureOutput = false usages = [] usageDisabled = false - epilog = undefined + epilogs = [] examples = [] commands = [] descriptions = objFilter(descriptions, (k, v) => !localLookup[k]) @@ -520,7 +520,7 @@ module.exports = function usage (yargs, y18n) { frozen.failureOutput = failureOutput frozen.usages = usages frozen.usageDisabled = usageDisabled - frozen.epilog = epilog + frozen.epilogs = epilogs frozen.examples = examples frozen.commands = commands frozen.descriptions = descriptions @@ -531,7 +531,7 @@ module.exports = function usage (yargs, y18n) { failureOutput = frozen.failureOutput usages = frozen.usages usageDisabled = frozen.usageDisabled - epilog = frozen.epilog + epilogs = frozen.epilogs examples = frozen.examples commands = frozen.commands descriptions = frozen.descriptions diff --git a/test/usage.js b/test/usage.js index 20be98b4d..f3c97252e 100644 --- a/test/usage.js +++ b/test/usage.js @@ -1943,6 +1943,28 @@ describe('usage tests', () => { ]) }) + it('supports multiple epilogs', () => { + const r = checkUsage(() => yargs('') + .epilog('for more info view the manual at http://example.com') + .epilog('you can also find us on slack at http://devtoolscommunity.herokuapp.com') + .epilog('keep up to date by reading our blog at http://yargs.js.org/blog.html') + .demand('y') + .wrap(null) + .parse() + ) + + r.errors.join('\n').split(/\n+/).should.deep.equal([ + 'Options:', + ' --help Show help [boolean]', + ' --version Show version number [boolean]', + ' -y [required]', + 'for more info view the manual at http://example.com', + 'you can also find us on slack at http://devtoolscommunity.herokuapp.com', + 'keep up to date by reading our blog at http://yargs.js.org/blog.html', + 'Missing required argument: y' + ]) + }) + it('replaces $0 in epilog string', () => { const r = checkUsage(() => yargs('') .epilog("Try '$0 --long-help' for more information")