-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
💸 $20A-deriveArea: #[derive]` macro APIArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsE-hardCall for participation: Experience needed to fix: Hard / a lotCall for participation: Experience needed to fix: Hard / a lotE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.
Milestone
Description
Maintainer's notes
- Deriving
Args
on an enum would create aArgGroup::new("T")::multiple(false)
- More builder methods can be accessed via
#[group(...)]
(split out as Implement more derive attributes for ArgGroup #4574)- We need to ensure overriding the group name works
- Variants without a type would be flags
- Tuple variants would be arguments like in a struct
- Flattening tuple variants would use
Args::group_id
, flattening struct variants would use the Variant.- Flattened struct variant fields should have their
Arg::id
set toVariant::field
, see Traefik-style `.` separated flag categories #4699.
- Flattened struct variant fields should have their
- Likely, we'll need to refactor
clap_derive
so we can share code between structs and enums - Note that nesting groups is problematic atm. See Create a group from an
Args
struct #3165 - Create a Traefik cookbook example based on notes in Traefik-style `.` separated flag categories #4699
Blocked on #3165 as that will lay some of the initial groundwork and #4211 to provide a fallback mechanism
Related
Please complete the following tasks
- I have searched the discussions
- I have searched the existing issues
Clap Version
3.0.0-beta.2
Describe your use case
I have multiple filters of witch only one can be set (--running
, --exited
, --restarting
,...).
Describe the solution you'd like
I would like something with this usage:
#[derive(Clap)]
pub struct App{
#[clap(flatten)]
pub state_filter: 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),
}
Resulting in:
OPTIONS:
--exited
Only exited servers are returned
--restarting
Only restarting servers are returned
--running
Only running servers are returned
--cusxtom <CUSTOM>
Alternatives, if applicable
I could use an arggroup for this currently, but I would still need to check each boolean separately and could not just easily (and readable) match
it.
Additional Context
No response
MTCoster, booniepepper, superatomic, HoloTheDrunk, Benricheson101 and 73 moreAntikyth, drahnr, DCjanus, schneiderfelipe, alexpovel and 3 more
Metadata
Metadata
Assignees
Labels
💸 $20A-deriveArea: #[derive]` macro APIArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsE-hardCall for participation: Experience needed to fix: Hard / a lotCall for participation: Experience needed to fix: Hard / a lotE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.