-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Create a group from an Args
struct
#3165
Comments
#4210 reserved some functionality in 4.0.0 that we could use for this. |
This implements the basics for clap-rs#3165, just missing - `flatten` support (waiting on improved group support) - `group` attributes
This will be needed when we support flattening for clap-rs#3165
This will be needed when we support flattening for clap-rs#3165
If the inner type never implemented `group_id()`, then it won't work and people will be confused. This at least gives people an idea of whats going wrong. This is most likely to be a problem until clap-rs#3165 is fully implemented but hand-implementations can still run into this. Probably should have made the groups another trait to catch this in type system but too late.
I was actually stumbling on this trying to design a shard set of options for dynamic completions. Would we support the use case of conflicting groups? I see two ways of doing it with increasing type safety (both not fully supported yet AFAICT): Semi-TypesafeType system ensures completeness of groups #[derive(Parser)]
struct CompleteArgs {
#[clap(flatten)]
register: Option<Register>,
#[clap(flatten)]
complete: Option<Complete>,
}
#[derive(Args)]
#[group(conflicts_with = Complete)]
struct Register {
#[arg(long)]
shell: String,
}
#[derive(Args)]
struct Complete {
#[arg(long)]
current: String,
} Fully-TypesafeType system ensures group conflict #[derive(Parser)]
struct CompleteArgs {
#[clap(arg_group)]
register_or_complete: RegisterComplete,
}
#[derive(ArgGroups)]
enum RegisterComplete {
Register(Register),
Complete(Complete),
}
#[derive(Args)]
struct Register {
#[arg(long)]
shell: String,
}
#[derive(Args)]
struct Complete {
#[arg(long)]
current: String,
} |
My expectation is we'll eventually support the fully type-safe solution as part of #2621 |
I'm going to consider this done with a known bug (#4697) |
Maintainer's notes
#[derive(Args)]
as anArgGroup
#4210Please complete the following tasks
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?
would have an implicitly created
ArgGroup::new("Group").multiple(true)
.You could then do
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 asclap::app
,.clap::args
, etc (#1553). Maybe that can help?Per-builder attributes are n
ow in
The text was updated successfully, but these errors were encountered: