From ca6c5d6faf27516b8d2532e60676a366ac55448d Mon Sep 17 00:00:00 2001 From: Cameron Hunter Date: Sun, 28 Jul 2019 22:20:42 -0700 Subject: [PATCH 1/2] Support multiple epilogs being added --- lib/usage.js | 14 +++++++------- test/usage.js | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/usage.js b/lib/usage.js index ded4fc427..0fa8f1201 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 4d211535d..58d91249f 100644 --- a/test/usage.js +++ b/test/usage.js @@ -1910,6 +1910,7 @@ describe('usage tests', () => { it('should display an epilog message at the end of the usage instructions', () => { 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') .demand('y') .wrap(null) .parse() @@ -1921,6 +1922,7 @@ describe('usage tests', () => { ' --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', 'Missing required argument: y' ]) }) From 6da9a6b08c00a1071f5d55d1522fb4bce4c79261 Mon Sep 17 00:00:00 2001 From: Cameron Hunter Date: Mon, 29 Jul 2019 15:29:59 -0700 Subject: [PATCH 2/2] Add a separate test case for multiple epilogs --- test/usage.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/usage.js b/test/usage.js index 58d91249f..ab94d19b2 100644 --- a/test/usage.js +++ b/test/usage.js @@ -1908,9 +1908,28 @@ describe('usage tests', () => { describe('epilogue', () => { it('should display an epilog message at the end of the usage instructions', () => { + const r = checkUsage(() => yargs('') + .epilog('for more info view the manual at http://example.com') + .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', + 'Missing required argument: y' + ]) + }) + + 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() @@ -1923,6 +1942,7 @@ describe('usage tests', () => { ' -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' ]) })