Skip to content

Create a group from an Args struct #3165

@epage

Description

@epage

Maintainer's notes


Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

3.0.0-rc.4

Describe your use case

I have a group of fields that I want to make a group for conflicting with other fields

Describe the solution you'd like

Inspired by #2621, what if we implicitly created a group from a struct?

#[derive(Args)]
struct Group {
    arg1: String,
    arg2: String
}

would have an implicitly created ArgGroup::new("Group").multiple(true).

You could then do

#[derive(Args)]
#[group(...group builder methods...)]
struct Group {
    arg1: String,
    arg2: String
}

Alternatives, if applicable

Manually define the args and deal with typos in arg and group names and issues like #2475

Additional Context

The big issue is defining this to not conflict with other app or group attributes. Somewhere I brought up the idea of more explicitly naming our attributes as clap::app,. clap::args, etc (#1553). Maybe that can help?

Per-builder attributes are n
ow in

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 / intermediate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions