Creating a clap subcommand in a library for use in an application

I'm working on a crate that has a context buffer that will very likely be configured from the command line. I want to provide an opt-in convenience implementation that clap users can add to their application.

Taken to it's almost extreme simplification, I want to create some entity that defines --name NAME as an argument and allow it to be added to their clap arg parser. I first started doing this using a pure derive solution, but the crux is that a name is required, and the application must provide a default:

pub fn crate_default_registration_args(name: &str) -> Something {
   let arg = Arg::something()

   // .. create other args, add them all to "something"


I would like application developers to be able to call crate_default_registration_args("mydefault") and stuff whatever it returns into a command or (more likely) a subcommand -- and have it work both using a Builder and derive.

Is this possible? (I realize the derive variant would require some hoops if it is at all possible).

clap can be kind of overwhelming -- I get the feeling that what I want to do is possible, but after reading what I believe are the relevant parts of the docs, I am not entirely sure.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.