Skip to content

Commit

Permalink
feat: adds support for multiple epilog messages (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronhunter authored and bcoe committed Jul 29, 2019
1 parent 28c74b9 commit 07a5554
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/usage.js
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
}

Expand Down Expand Up @@ -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])
Expand All @@ -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
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/usage.js
Expand Up @@ -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")
Expand Down

0 comments on commit 07a5554

Please sign in to comment.