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

Automatically defer subcommand initialization for derives #4959

Open
2 tasks done
epage opened this issue Jun 9, 2023 · 0 comments
Open
2 tasks done

Automatically defer subcommand initialization for derives #4959

epage opened this issue Jun 9, 2023 · 0 comments
Labels
A-derive Area: #[derive]` macro API C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Milestone

Comments

@epage
Copy link
Member

epage commented Jun 9, 2023

Please complete the following tasks

Clap Version

4.3.3

Describe your use case

#4792 added deferred command initialization but no support exists yet for the derive API.

Describe the solution you'd like

Automatically defer all non-essential subcommand calls.

Alternatives, if applicable

No response

Additional Context

Automatic deferment would be a breaking change though we could make it opt-in through the remainder of 4.x

A rough sketch

  • Extend Args to have defer_augment_args
  • Extend Subcommand to have defer_augment_subcommand
  • New #[command(defer = <bool>)] magic attribute
    • defaults to false in clap v4
    • defaults to true in clap v5, mark it as deprecated
    • remove it in clap v6
  • If defer = false on a top-level container, always call defer_augment_args along with augment_args
  • If defer = true on a top-level container
    • Defer Command::subcommand and Command::arg calls
    • if defer = true on a flatten, augment_args only calls the same of its children
    • If defer = false on a flatten, defer augment_args until when defer_augment_args is called
@epage epage added C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change. A-derive Area: #[derive]` macro API labels Jun 9, 2023
@epage epage added this to the 5.0 milestone Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-derive Area: #[derive]` macro API C-enhancement Category: Raise on the bar on expectations M-breaking-change Meta: Implementing or merging this will introduce a breaking change.
Projects
None yet
Development

No branches or pull requests

1 participant