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

refactor(derive): Always do app_methods last #2819

Merged
merged 2 commits into from
Oct 7, 2021
Merged

Conversation

epage
Copy link
Member

@epage epage commented Oct 5, 2021

By doing this, we can revert TeXitoi/structopt#325 since we no longer need to special case version.

I was hoping to move app methods first, but this is some clean in the complete opposite direction up as I think further about the problem. The issue is with subcommands which need to call into the Args for each variant and it needs the subcommand App to be initialized by the Args, followed by the variant's app methods overriding that.

This will unblock us from removing the `version` hack because we'll
always get the right precedence.

Later we can explore ways of moving the app methods to being done first.
The big problem is with `#[clap(subcommand)]` because we need to call
those app methods on the subcommands `App` *and* override them with app
methods on the variant, requiring the app methods to be last to get
precedence.
TeXitoi/structopt#325 special cased `version`
because a default method would be added if the user did nothing, which
caused problems when nesting subcommands.  We no longer apply that
default method and the highest item in the chain always has precedence,
so this can be simplified / clarified.
@epage epage added the M-unreviewed Meta: Request for post-merge review. label Oct 7, 2021
@epage epage merged commit 8eb4377 into clap-rs:master Oct 7, 2021
@epage epage deleted the consistent branch October 7, 2021 14:04
@pksunkara pksunkara removed the M-unreviewed Meta: Request for post-merge review. label Oct 9, 2021
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.

None yet

2 participants