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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: improve support for async/await #1823
Conversation
For anyone who would like to try this and give feedback (which is greatly appreciated):
|
@mleguen @SkeLLLa @petrgrishin @dapplion this PR removes I would love your feedback. You can install this version of yargs like so:
|
The overall direction looks great! Can't wait to have this on master |
docs/advanced.md
Outdated
|
||
If you use async middleware or async handlers for commands, `yargs.parse` and | ||
`yargs.argv` will return a Promise. When you `await` this promise the final | ||
parsed result will be returned: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a note that this will be returned after the handler has finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
I was surprised and disappointed by the removal of
|
@bcoe The typing is wrong. See my comment in #2175 (comment). |
In
node@15
top level await is now supported 馃帀.This means that we can have yargs return a promise in more situations, with users writing code that looks like this:
This PR begins work to add better first class support of promises to yargs.
TODO:
write unit tests for scenarios outlined in Accepting sync and async callbacks while keeping yargs functions sync-only is incoherent聽#1420broke into several steps..parse()
(Refs: Accepting sync and async callbacks while keeping yargs functions sync-only is incoherent聽#1420)..argv
(Refs: Accepting sync and async callbacks while keeping yargs functions sync-only is incoherent聽#1420).should command builders accept a promise?see Allow command builder to accept a promise聽#1042 -- we will land this work separately before the next major.add async support to coerce/check, see Ability to do async stuff in check() and coerce()聽#859 -- we will land this work separately before the next major.make global middleware work without defining command (this work should be in separate breaking PR).broken into ticket Registered middleware should be called even if no commands are defined聽#1849BREAKING CHANGES:
async
.err
and `completions, returns promise of completions.Fixes #1791, #1420, #1235