Skip to content
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

Description of flattened struct overwrites app description #539

Closed
palant opened this issue May 8, 2024 · 1 comment
Closed

Description of flattened struct overwrites app description #539

palant opened this issue May 8, 2024 · 1 comment

Comments

@palant
Copy link

palant commented May 8, 2024

Consider the following application:

use structopt::StructOpt;

/// Inner description
#[derive(Debug, StructOpt)]
struct OptInner {}

/// Outer description
#[derive(Debug, StructOpt)]
struct OptOuter {
    #[structopt(flatten)]
    inner: OptInner
}

fn main() {
    OptOuter::from_args();
}

Running cargo run -- -h produces the following help text:

test 0.1.0
Inner description

USAGE:
    test

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

Note that the application description belongs to OptInner, not OptOuter as expected. Running cargo expand shows the issue:

let app = app.about("Outer description");
let app = <OptInner as ::structopt::StructOptInternal>::augment_clap(app);

So this first applies the attributes of the outer structure and calls augment_clap() of the inner structure then which will overwrite them.

The equivalent clap code does that in reverse order, producing the correct result:

let __clap_app = <OptInner as clap::Args>::augment_args(__clap_app);
__clap_app.about("Outer description").long_about(None)

For reference: clap-rs/clap#2527

@TeXitoi
Copy link
Owner

TeXitoi commented May 8, 2024

Duplicate of #333

@TeXitoi TeXitoi marked this as a duplicate of #333 May 8, 2024
@TeXitoi TeXitoi closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants