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
Allow command builder to accept a promise #1042
Comments
This feature would be great. A real life example why it's needed, is here: https://github.com/stepweb/github/blob/master/src/commands/query/builder.js#L4 This is a GitHub GraphQL CLI that queries GitHub's API to resolve what the various possible commands are. However, since builder() doesn't support async, we need to compensate for this deficiency by front-loading all commands at boot-up (which is obviously not ideal since we're loading even things the user might not need). |
Any update ? |
👋 I think it would potentially be a fairly major overhaul to yargs to allow a builder to be asynchronous. This functionality would be super cool, but it might not be something we can easily offer in the immediately future -- the problem being the expectation that I wonder if it would be worth creating a new project ... call it |
@bcoe I think to add a new api returns Promise instead of create a new package would be a good choice. for example
You can ignore a promise return value in sync mode and await promise in async mode. |
@XGHeaven @quilicicf my thinking was that we could do this in the next major version of yargs, ideally once top level await is supported. I believe we will need a bit of an overhaul of how we handle asynchronous behavior to get things right. |
That would be great 👍 |
I would like to investigate landing this work before we release the next major version of yargs. Refs: #1823 |
@quilicicf @adamovsky could I ask you to try If you provide an |
I'm setting up a reminder, will try to do that in the coming days 👍 |
Hey @bcoe, I have played around a bit with the async builder, it works like a charm with a little caveat I didn't expect: displaying the help calls the async builder, which means that in my use-case, the user is prompted for configuration before they get to see the command's help text. I'm wondering if this can be worked around. An example of the precise case where this can happen.
I'm wondering if yargs could give the builder the knowledge about whether the command was run with |
@quilicicf I think we need to execute the builder, before help, otherwise we can't show information like default values (if they're configured in the builder). I like the idea of providing a second parameter to the builder that indicates whether it's |
It'd be awesome to have this |
@quilicicf could you try |
Fixes: #1042 BREAKING CHANGE: providing an async builder will now cause yargs to return async result BREAKING CHANGE: .positional() now allowed at root level of yargs.
Will do! @bcoe |
Works like a charm! |
Feature request
Allow the command builder to accept a promise like follows:
This feature is the same as the one from #510 but for the command builder.
Use case
The defaults of a command's parameter depend on the configuration of the app.
In some cases the configuration is not defined => the app prompts the user and helps him bootstrap the configuration then runs the initial command.
The command builder needs to be async.
The text was updated successfully, but these errors were encountered: