Async `choices` for `.argument()`?
khill-fbmc opened this issue · 7 comments
Is it possible to fetch a list of users let say, and have that displayed as the choices? I get that this would need to be typed, by my own interface perhaps, but would make it easy do work based on the results of a fs or api call.
Interesting idea. yargs
doesn't support this out of the box, and it would take some effort to implement this without surprising users. E.g. currently the choices are listed in the --help
output, and I could imagine the list to grow too large. Also, an async call could take a while, and this could impact the response time of commands. Some loading indicator would be advised. Caching could speed things up in a REPL interface where choices are used for autocompletion. Etc. I'll keep this issue open but unfortunately I don't expect to be able to work on this in the short term.
All valid points! I was starting to dig into a little and realized how complex a simple ask is, haha!
yargs doesn't support this out of the box
This idea has been stuck in my 🧠 so I was just digging in your lib and the sources, checking out how it works and found that you allow customizing yargs so I followed the url you linked and what if I create a middleware to load my choices?!?!!?
Can't find anything in this article which indicates that choices
can be an (async) function.
[...] what if I create a middleware to load my choices?!?!!?
I'm not familiar with yargs middleware, but I would be interested to hear if you're able to build something to support this use case!
I don't like dangling issues in my repos, so I'm going to close this for now.
I don't want to leave it open like I'm actively looking for an answer.