Ability to do async stuff in check() and coerce() #859
Comments
It seems like yargs could check the |
It'd probably still be nice for const awaitCoercions = argv => Promise.all(
Object.entries(argv).map(async ([key, value]) => {
// Awaiting a non-promise just returns the value itself
argv[key] = await value
})
)
yargs
.scriptName('your-script-name')
// ...
.middleware([awaitCoercions])
.argv |
@TomerAberbach I've been threatening to do this, for perhaps a year, but I would like to sit down and write a design document for how yargs handles async ... these features have grown organically. |
@bcoe Let me know if you need any help! Feel free to ping me on the Slack |
@TomerAberbach where things get a little sticky with coerce, is the method is actually applied in yargs-parser. Which was designed to be synchronous. How I might approach things, would be to allow Where I think we might need a design document, is that I'd be interested in moving towards something like this: const args = await yargs.parseAsync()
... maybe we could even consider retiring some of the less thought out async behavior, and isolating it behind this new method. |
@bcoe I'd be happy to try to put together a design document. I expect to be a bit busy with other things in the next few weeks, but I'll see what work I can fit in. If I don't find the time, then I'll work on it a few weeks from now. |
@TomerAberbach sounds great We're pretty close to the TypeScript conversion, so things might time really well, where we can take on the async problem immediately afterwards. |
@bcoe Just curious, any idea if we can expect the Cheers ! |
@Niceplace I know I'd like to solve the problem in the not too distant future, as with ESM starting to get some traction, But, I have almost no time to work on this, and it's a major project, so I'm not sure. |
I would like to investigate landing this feature as part of the major release being worked on here: |
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 https://github.com/davidtheclark/cosmiconfig, 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
: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.
The text was updated successfully, but these errors were encountered: