Skip to content

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

Description

@satazor

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:

const argv = await yargs()
.strict()
.option('config', {
  type: 'string',
  coerce: () => cosmiconfig('my-app'),
})
.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.

❤️ yargs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions