These are chat archives for kbknapp/clap-rs

Jun 2018
Vasyl Purchel
Jun 11 2018 23:36

hi, so I've been digging for a bit this and I can't find how/if rustup is using it though I found how cargo does that and I think it's something similar to what I was looking for:
from each plugin cargo requires to implement command metadata and this will return json object that can be used to build a command in main app, so you'll get help and completions there.

so before I'll get deep into implementing my own json structure for this, is there an easy way to dump clap app into json and then deserialise into subcommand or is it something that needs to be implemented?

Kevin K.
Jun 11 2018 23:57
@vasyl-purchel sorry if I wasn't clear - rustup isn't using AllowExternalSubcommands however one of their subcommands completions does generate the completions for the rustup binary dynamically at runtime. So I was suggesting using that as an example of how the completions could be generated at runtime for your external subcommand plugins
This could be done by either having the main binary "know" about some hidden argument which generates the completions for the plugin, and all supported plugins would simply "implement this hidden argument" if they wish to support said feature
...actually that's probably best way :P
I was going to list another way to implement it, but it's not nearly as good