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

Support Option<T> when flattening #4211

Closed
2 tasks done
epage opened this issue Sep 13, 2022 · 2 comments
Closed
2 tasks done

Support Option<T> when flattening #4211

epage opened this issue Sep 13, 2022 · 2 comments
Labels
A-derive Area: #[derive]` macro API C-enhancement Category: Raise on the bar on expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Experience needed to fix: Medium / intermediate 💸 $20 S-blocked Status: Blocked on something else such as an RFC or other implementation work.
Milestone

Comments

@epage
Copy link
Member

epage commented Sep 13, 2022

Please complete the following tasks

Clap Version

4.0.0

Describe your use case

When flattening, I'd like to make the struct optional

#[derive(Clap)]
pub struct App{
    #[clap(flatten)]
    pub state_filter: Option<StateFilter>,
}

#[derive(Args)]
pub enum StateFilter {
    /// Only running servers are returned
    #[clap(long)]
    Running,
    /// Only exited servers are returned
    #[clap(long)]
    Exited,
    /// Only restarting servers are returned
    #[clap(long)]
    Restarting,
    #[clap(long)]
    Custom(String),
}

Describe the solution you'd like

With #3165, we could check if the ArgGroup is present and, if it isn't, return None. Otherwise, we walk into the ArgGroup and access it.

Alternatives, if applicable

No response

Additional Context

No response

@epage epage added C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate A-derive Area: #[derive]` macro API 💸 $20 S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Sep 13, 2022
@epage epage added the E-help-wanted Call for participation: Help is requested to fix this issue. label Sep 20, 2022
@epage epage added this to the 4.x milestone Sep 29, 2022
@epage
Copy link
Member Author

epage commented Oct 5, 2022

Oops, looks like we already have #3123, closing in favor of that though #4350 is just about to be merged, supporting this

@epage epage closed this as completed Oct 5, 2022
@epage
Copy link
Member Author

epage commented Oct 5, 2022

v4.0.10

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 E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Experience needed to fix: Medium / intermediate 💸 $20 S-blocked Status: Blocked on something else such as an RFC or other implementation work.
Projects
None yet
Development

No branches or pull requests

1 participant