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

fix(derive): Ensure App help_heading is applied #2882

Merged
merged 1 commit into from
Oct 16, 2021

Conversation

epage
Copy link
Member

@epage epage commented Oct 15, 2021

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 #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 #2785

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
@epage epage added the M-unreviewed Meta: Request for post-merge review. label Oct 16, 2021
@epage
Copy link
Member Author

epage commented Oct 16, 2021

I know I've not given much time for people to review this (especially since derives can be a bit rougher to review) but the high level goal is not controversial and I have some other changes I'm wanting to get this in tonight to get several other changes blocked on this in tomorrow morning.

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 16, 2021

Build succeeded:

@bors bors bot merged commit 6eacd8a into clap-rs:master Oct 16, 2021
@pksunkara
Copy link
Member

I have not reviewed this because I wanted to see if there's a way we can avoid doing it like this. I didn't like the fact that we divided these methods into first and last. With the recent fixes to help_heading, wouldn't applying all the methods first (like it was before) fix it? Don't think this PR is really needed.

@epage epage deleted the help_heading branch October 16, 2021 14:46
@epage
Copy link
Member Author

epage commented Oct 16, 2021

I have not reviewed this because I wanted to see if there's a way we can avoid doing it like this. I didn't like the fact that we divided these methods into first and last. With the recent fixes to help_heading, wouldn't applying all the methods first (like it was before) fix it? Don't think this PR is really needed.

For now, we need to apply the methods last so that when we flatten, the higher level struct's app settings win (#2531).

In parallel, I've been working towards changing how we model app settings and would split those out so that a flattened struct will never impact the higher level struct. That is a bigger, more experimental of a change that I think is a lower priority for 3.0 than this change and wanted to make progress on this bug rather than block a fix on that experiment.

Copy link
Member

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. Just two comments that needs to be resolved.

clap_derive/src/parse.rs Show resolved Hide resolved
@pksunkara
Copy link
Member

In parallel, I've been working towards changing how we model app settings and would split those out so that a flattened struct will never impact the higher level struct.

To confirm, that is tracked in #2894, right?

@pksunkara pksunkara removed the M-unreviewed Meta: Request for post-merge review. label Oct 16, 2021
#( #subcommands )*;
#app_var #app_methods
#app_var #final_app_methods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have tests for some of the changes in these files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added in #2895

@epage
Copy link
Member Author

epage commented Oct 16, 2021

In parallel, I've been working towards changing how we model app settings and would split those out so that a flattened struct will never impact the higher level struct.

To confirm, that is tracked in #2894, right?

Now it is, yes.

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

Successfully merging this pull request may close these issues.

Section headings don't match contents
2 participants