-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to create a global template #1184
Comments
Totally agree this is a lacking feature, thanks for the suggestion! In order for me to actually get v3 released I have to put blinders on and only implement bug fixes or super trivial features which are simple to forward port to the v3 branch. I don't know that this is one such issue. I'll leave it open for v3 as it is something I do want to have. Having said all this, if someone implements this for v2 I'm not against the PR, so long as the understanding is that for v3 I may have to rip out the commit and re-do it depending how deep into the internals it gets to implement this. (for v3 the internals are quite different, so some changes aren't trivial to forward port). |
To solve this, we would either need to add a |
One idea I have for this (and other issues) is if we implemented a layered config. Some fields would be designated as layered, like this, and others would not, like a subcommands display order. For layered fields, we propagate them to subcommands if they are set in the parent but not the sucommand, and then continue this recursively. So build would have code like:
|
I think you might need to expand on this. I am quite confused reading your comment. |
Yeah, I can see needing to re-phrase since i'm using a term in an adjacent domain for which we have feature requests ;). What if we modeled clap's builder API after layered config? What I mean is where you take configuration from different sources and merge them together. The approach I've taken in several applications that I've been finding works well is that the config data tracks what is explicitly set, using So what this would look like in if let Some(help_template) = self.help_template.as_deref() {
subcommand.help_template.get_or_insert(help_template)
} This will preserve the subcommands original help template. If it was never explicitly set by the user, the parent command's help template would be used. Depending on performance, we might also apply the default layer so that the accessors don't have to re-compute it on each call.
|
clap unfortunately doesn't support sharing help templates between subcommands; see clap-rs/clap#1184. But as it will turn out, we don't *just* want to share a single template, but conditionally add certain snippets to the `Usage:` section of certain subcommands, depending on their arguments. Also, given our plans, the const_format crate isn't really worth it just for those {INDENT}s… Part of P0266, funded by Ember2528.
Affected Version of clap
2.29.4
Expected Behavior Summary
Being able to call
global_template
and have the template propagate down to subcommands.Actual Behavior Summary
For every single subcommand, I have to add a
template
call to get them all to match my custom template.The text was updated successfully, but these errors were encountered: