-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
add ability to parse additional group methods #4688
Conversation
2d3acf1
to
931eac5
Compare
tests/derive/groups.rs
Outdated
use clap::CommandFactory; | ||
let source_id = clap::Id::from("Source"); | ||
let dest_id = clap::Id::from("Dest"); | ||
let opt_command = Opt::command(); | ||
let source_group = opt_command | ||
.get_groups() | ||
.find(|g| g.get_id() == &source_id) | ||
.unwrap(); | ||
let dest_group = opt_command | ||
.get_groups() | ||
.find(|g| g.get_id() == &dest_id) | ||
.unwrap(); | ||
assert!(source_group.is_required_set()); | ||
assert!(dest_group.is_required_set()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally we do integration tests where we verify the behavior of the feature, like with assert_output
Thanks for moving this forward! |
840978f
to
19f3b37
Compare
@epage I've made this more general, which I think addresses your comment about switching to a |
match kind { | ||
AttrKind::Group => self.group_methods.push(Method::new(name, quote!(#arg))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test where the group's id
is overridden? I think that will break and instead overwrite the command's name.
Similarly, we need a ui-test
ensuring that #[group(name = "foo")]
fails as name
isn't a group attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ui-test
exists but not the overridden id
.
The problem I'm trying to highlight is that we are only setting group_methods
in one branch and instead setting things on the Command
in the other branches.
Maybe we should have a push_group_method
function and make the switch between them higher up.
Yes it is, thanks! |
This adds the "required" derive option for the group creation. Needed for clap-rs#4574.
@epage I have a question I was hoping you might be able to help me with. I can't figure out how to address the tests in I've never seen a dedicated |
Normally To run a specific test for derive, it would be You would also run |
This adds the ability derive additional options for the group creation. Needed for clap-rs#4574.
19f3b37
to
f281c67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for continuing to move this forward!
.find(|g| g.get_id() == &source_id) | ||
.unwrap(); | ||
assert!(source_group.is_required_set()); | ||
// assert!(source_group.is_multiple()); currently broken. Fixed by PR #4704 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a note about this on the issue, not PR (as PRs come and go) and delete it.,
As-is, we have no way to track fixing this and it will get lost.
let source_id = clap::Id::from("Source"); | ||
let opt_command = Opt::command(); | ||
let source_group = opt_command | ||
.get_groups() | ||
.find(|g| g.get_id() == &source_id) | ||
.unwrap(); | ||
assert!(source_group.is_required_set()); | ||
// assert!(source_group.is_multiple()); currently broken. Fixed by PR #4704 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also tend to test the behavior from setting things rather than checking that they are set.
match kind { | ||
AttrKind::Group => self.group_methods.push(Method::new(name, quote!(#arg))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ui-test
exists but not the overridden id
.
The problem I'm trying to highlight is that we are only setting group_methods
in one branch and instead setting things on the Command
in the other branches.
Maybe we should have a push_group_method
function and make the switch between them higher up.
FYI I've done some more work on this and closing this PR in favor of #4795 |
@epage Cheers :) |
Towards completing #4574 , let's add the other methods for
group
derive.This is my first PR for Clap and a lot of this was Cargo coding.
Please forgive anything that seems silly.
I'm very open to feedback :)