Skip to content

Commit

Permalink
Fix issue 1533
Browse files Browse the repository at this point in the history
  • Loading branch information
Mael LE GUEN committed Jan 29, 2020
1 parent 0f4e8ca commit e36667e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/command.js
Expand Up @@ -256,6 +256,9 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
// fail's throwing would cause an unhandled rejection.
}
})
.then(() => {
yargs.getUsageInstance().clearCachedHelpMessage()
})
} else {
if (handlerFinishCommand) {
handlerFinishCommand(handlerResult)
Expand Down
6 changes: 6 additions & 0 deletions lib/usage.js
Expand Up @@ -411,6 +411,12 @@ module.exports = function usage (yargs, y18n) {
cachedHelpMessage = this.help()
}

// however this snapshot must be cleared afterwards
// not to be be used by next calls to parse
self.clearCachedHelpMessage = function () {
cachedHelpMessage = undefined
}

// given a set of keys, place any keys that are
// ungrouped under the 'Options:' grouping.
function addUngroupedKeys (keys, aliases, groups) {
Expand Down
4 changes: 2 additions & 2 deletions test/usage.js
Expand Up @@ -3432,7 +3432,7 @@ describe('usage tests', () => {
})

describe('help message caching', () => {
it.only('should display proper usage when an async handler fails', (done) => {
it('should display proper usage when an async handler fails', (done) => {
const y = yargs()
.command('cmd', 'test command', {}, () => {
return new Promise((resolve, reject) =>
Expand Down Expand Up @@ -3464,7 +3464,7 @@ describe('usage tests', () => {
)
})

it.only('should not display a cached help message for the next parsing', (done) => {
it('should not display a cached help message for the next parsing', (done) => {
const y = yargs()
.command('cmd', 'test command', {}, () => {
return new Promise((resolve, reject) =>
Expand Down

0 comments on commit e36667e

Please sign in to comment.