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

fix: always cache help message when running commands #1865

Merged
merged 1 commit into from Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions lib/command.ts
Expand Up @@ -338,8 +338,8 @@ export function command(
}
}

yargs.getUsageInstance().cacheHelpMessage();
if (isPromise(innerArgv) && !yargs._hasParseCallback()) {
yargs.getUsageInstance().cacheHelpMessage();
innerArgv.catch(error => {
try {
yargs.getUsageInstance().fail(null, error);
Expand All @@ -348,8 +348,6 @@ export function command(
// registered, run usage's default fail method.
}
});
} else if (isPromise(innerArgv)) {
yargs.getUsageInstance().cacheHelpMessage();
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/yargs.cjs
Expand Up @@ -3065,5 +3065,19 @@ describe('yargs dsl tests', () => {
commandCalled.should.equal(false);
middlewareCalled.should.equal(false);
});
// Refs: #1853
it('should use cached help message for nested synchronous commands', async () => {
const y = yargs('object').command(
'object',
'object command',
(yargs) => {
yargs.command('get', 'get command');
}
);
const argv = y.argv;
const help = (await y.getHelp());
help.should.match(/node object get/);
argv._.should.eql(['object']);
});
});
});