I’m trying to write a command line utility which I’d like to be easily extensible, and the model that cargo and git both use - using third-party binaries for executing certain subcommands - seems like the way I’d like to go. I’m hoping to use clap for structuring the top-level binary’s argument parsing. I see that clap claims to be able to delegate unmatched subcommands to external subcommands, but I’m unable to find much detail on how that interaction works. I’d like to see how the top-level command and sub-commands interact.
I’m trying to sift through cargo’s source to understand how it implements its subcommand interface, and I’ve found this spot in the code where it seems to find the subcommand executable in the PATH and forward its arguments to it. Cargo uses its own subcommand forwarding, however (i.e. it doesn’t use clap), but it seems that the packages that are subcommands to cargo can manage to use clap to receive the invocation from the top-level cargo binary (such as cargo-update).
My ultimate goal is to make a pair of binaries which can both be used independently, but where the top-level binary behaves like cargo, forwarding calls of a specific subcommand to the other binary. If anybody has any insight on this, I’d greatly appreciate it!