Skip to content

Support Option<T> when flattening #4211

Closed
@epage

Description

@epage
Member

Please complete the following tasks

  • I have searched the discussions
    I have searched the open and rejected issues

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

Activity

added
C-enhancementCategory: Raise on the bar on expectations
E-mediumCall for participation: Experience needed to fix: Medium / intermediate
A-deriveArea: #[derive]` macro API
S-blockedStatus: Blocked on something else such as an RFC or other implementation work.
on Sep 13, 2022
added
E-help-wantedCall for participation: Help is requested to fix this issue.
on Sep 20, 2022
added this to the 4.x milestone on Sep 29, 2022
epage

epage commented on Oct 5, 2022

@epage
MemberAuthor

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

epage

epage commented on Oct 5, 2022

@epage
MemberAuthor

v4.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    💸 $20A-deriveArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsE-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Experience needed to fix: Medium / intermediateS-blockedStatus: Blocked on something else such as an RFC or other implementation work.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @epage

        Issue actions

          Support `Option<T>` when flattening · Issue #4211 · clap-rs/clap