-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Section headings don't match contents #2785
Comments
Thanks for digging into this more than needed. Always appreciate the extra info. |
My proposal is still the same, we revert #2531 and instead move setting of help/about to |
@pksunkara I wouldn't classify this as easy until we have a decision made on what we want the behavior to be because |
Note: this can be worked around by setting the help heading on each arg. Not ideal but one way to be unblocked. |
I think just the first arg in each flattened struct should be enough as a workaround IIRC. #[derive(Debug, Clone, Clap)]
struct OptionsA {
#[clap(long)]
#[clap(help_heading = "HEADING A")]
should_be_in_section_a: Option<u32>,
} |
I will leave the decision of 3.0 milestone to you. I am not sure if what you are proposing needs breaking changes or not. |
Thanks for the quick replies!
It looks like it needs to be set on each individually: use clap::Clap;
#[derive(Debug, Clone, Clap)]
struct CliOptions {
#[clap(flatten)]
options_a: OptionsA,
#[clap(flatten)]
options_b: OptionsB,
}
#[derive(Debug, Clone, Clap)]
struct OptionsA {
#[clap(long)]
#[clap(help_heading = Some("HEADING A"))]
should_be_in_section_a: Option<u32>,
#[clap(long)]
should_also_be_in_section_a: Option<u32>,
}
#[derive(Debug, Clone, Clap)]
struct OptionsB {
#[clap(long)]
#[clap(help_heading = Some("HEADING B"))]
should_be_in_section_b: Option<u32>,
#[clap(long)]
should_also_be_in_section_b: Option<u32>,
}
fn main() {
CliOptions::parse();
}
|
My proposed change would not be an API breakage but a behavior breakage (expectations for what deriving |
Thanks for confirming this. I was making my assumption based on doc string
https://docs.rs/clap/3.0.0-beta.4/clap/struct.Arg.html#method.help_heading |
Ah, I was confusing that with https://docs.rs/clap/3.0.0-beta.4/clap/struct.App.html#method.help_heading |
Before clap-rs#2005, `Clap` was a special trait that derived all clap traits it detected were relevant (including an enum getting both `ArgEnum`, `Clap`, and `Subcommand`). Now, we have elevated `Clap`, `Args`, `Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't very descriptive. This also helps further clarify the relationships so a crate providing an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely to choose the needed trait to derive. Also, my proposed fix fo clap-rs#2785 includes making `App` attributes almost exclusively for `Clap`. Clarifying the names/roles will help communicate this. For prior discussion, see clap-rs#2583
Before clap-rs#2005, `Clap` was a special trait that derived all clap traits it detected were relevant (including an enum getting both `ArgEnum`, `Clap`, and `Subcommand`). Now, we have elevated `Clap`, `Args`, `Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't very descriptive. This also helps further clarify the relationships so a crate providing an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely to choose the needed trait to derive. Also, my proposed fix fo clap-rs#2785 includes making `App` attributes almost exclusively for `Clap`. Clarifying the names/roles will help communicate this. For prior discussion, see clap-rs#2583
Before clap-rs#2005, `Clap` was a special trait that derived all clap traits it detected were relevant (including an enum getting both `ArgEnum`, `Clap`, and `Subcommand`). Now, we have elevated `Clap`, `Args`, `Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't very descriptive. This also helps further clarify the relationships so a crate providing an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely to choose the needed trait to derive. Also, my proposed fix fo clap-rs#2785 includes making `App` attributes almost exclusively for `Clap`. Clarifying the names/roles will help communicate this. For prior discussion, see clap-rs#2583
Before clap-rs#2005, `Clap` was a special trait that derived all clap traits it detected were relevant (including an enum getting both `ArgEnum`, `Clap`, and `Subcommand`). Now, we have elevated `Clap`, `Args`, `Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't very descriptive. This also helps further clarify the relationships so a crate providing an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely to choose the needed trait to derive. Also, my proposed fix fo clap-rs#2785 includes making `App` attributes almost exclusively for `Clap`. Clarifying the names/roles will help communicate this. For prior discussion, see clap-rs#2583
We normally set all app attributes at the end. This can be changed but will require some work to ensure - Top-level item's doc cmment ins our over flattened - We still support `Args` / `Subcommand` be used to initialize an `App` when creating a subcommand In the mean time, this special cases `help_heading` to happen first. We'll need this special casing anyways to address clap-rs#2803 since we'll need to capture the old help heading before addings args and then restore it after. I guess we could unconditionally do that but its extra work / boilerplate for when people have to dig into their what the derives do. Fixes clap-rs#2785
Please complete the following tasks
Rust Version
rustc 1.55.0 (c8dfcfe04 2021-09-06)
Clap Version
master
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
Expected Behaviour
Additional Context
This was broken by #2531.
Debug Output
No response
The text was updated successfully, but these errors were encountered: