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

Ability to do async stuff in check() and coerce() #859

satazor opened this Issue Apr 18, 2017 · 1 comment


None yet
2 participants

satazor commented Apr 18, 2017

Sometimes you may want to coerce an option but the coercing itself is async. My specific use case was to coerce --config with the output of, but this might be handy in other situations.

Supporting this would probably require a lot of work, perhaps the maintainers could weight what would need to be changed. In terms of API, nothing would change, except for the .argv:

const argv = await yargs()
.option('config', {
  type: 'string',
  coerce: () => cosmiconfig('my-app'),

Though, this would be a breaking change. Perhaps, we could have another prop, say .argvPromise to accomplish the same goal.

This thread is to create a discussion about this feature. Feel free to ditch it if it introduces too much complexity.

❤️ yargs


This comment has been minimized.

ljharb commented Apr 14, 2018

It seems like yargs could check the .length of the coerce function; if it's 0, expect sync, if it's 1, it will get a callback that's async (and could also await the return value)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment