These are chat archives for kbknapp/clap-rs

8th
Jun 2018
Vasyl Purchel
@vasyl-purchel
Jun 08 2018 16:31
hey guys, does anyone have an example using clap with external subcommands? :)
Kevin K.
@kbknapp
Jun 08 2018 16:34
@vasyl-purchel there should be one in the examples directory, or on docs.rs/clap
One sec I'll get a link
(I'm on mobile)
@hstefan I haven't had time to look at the PR yet, but should soon ;)
Vasyl Purchel
@vasyl-purchel
Jun 08 2018 16:37
oh, yes, I saw that one, I'm more interested in full working example with plugins... in particular interested in how to make gen_completions_to to include external plugins :)
Kevin K.
@kbknapp
Jun 08 2018 16:38
Aaah ok I see! Hmm, I'm not sure I have any examples like that. I'm actually not sure how I would be able to generate completions from external subcommands
Because the completions work by internally viewing the clap::App struct
Which external subcommands may not have of they are just a random binary
If*
Vasyl Purchel
@vasyl-purchel
Jun 08 2018 16:40
yup, I was thinking on doing something like calling completions command on external plugins, same for help, though not sure how to feed the output to core application...
i.e. coreapp completions bash will go through each registered external subcommand for example coreapp-plugin and call coreapp-plugin completions bash (let's assume external plugin uses clap also)
Kevin K.
@kbknapp
Jun 08 2018 16:44
So if the external command was written with clap then it's probably possible if we added some additional API to somehow pass the clap::App struct or the completions info
Ah gotcha yeah
So I don't have any premade examples like that but would be happy to help you along in making it
I'm just not a computer right now so I can't do it right now
The closet you'll find is if you look at the rustup source
For their completions command and see how it generates the completions script at runtime
Each of your external subcommands would need to do something like that
Vasyl Purchel
@vasyl-purchel
Jun 08 2018 16:49
cool, thanks, will take a look :) if I'll get something I'll try send PR (though I only started learning rust few weeks ago so probably will need some work before merging it :) )
Kevin K.
@kbknapp
Jun 08 2018 16:53
No worries, I'm glad to help where I can :)
Vasyl Purchel
@vasyl-purchel
Jun 08 2018 17:22
hm... looking at rustup code if I'm checking the right place (master branch at https://github.com/rust-lang-nursery/rustup.rs) it looks like AppSettings::AllowExternalSubcommands is not used and I don't see it's generating completions for external subcommands... so far I can't figure out how it's using external subcommands...