Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple epilogs being added #1384

Merged
merged 2 commits into from Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions test/usage.js
Expand Up @@ -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()
Expand All @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add one additional test with multiple epilogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Added.

'Missing required argument: y'
])
})
Expand Down