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
Overhaul ArgParse to make it more like python argparse #2531
Conversation
At first glance this seems like a nice change. I prefer the style that binds the option to a specific variable directly, rather querying it in a second place with Overall LGTM! |
Right, I'm using a mix of styles currently. This is some combination of (a) I'm not sure what I prefer myself yet! (b) Laziness, I did kind of a more straightforward conversion to an intermediate step I had devised, then later worked my way to the full argparse implementation and only in a few cases did I return and fix all the uses. At some point, the conversion of all the uses was grueling and I just wanted to get a draft posted and merged. I will probably continue to change how I use it in different places, but I just wanted to finally push this out after months of tinkering. I think there are three different "styles", each of which I prefer in different situations:
|
I've been thinking about overhauling ArgParse for a couple years, and did most of the work in December when I was home from work. Then sat on it except for slow burn weekend tinkering, but finally got a chance to put the final touches on and write the docs this week. The bottom line is that this is a major rewrite of the APIs for ArgParse to make them much richer, more flexible, and more closely resembling those of python's argparse module. Rather than trying to explain the syntax here, I simply will refer you to the extensive inline documentation in argparse.h, as well as the examples in the code base of where it's used. It sill respects the old syntax, so this change is hoped to not alter the behavior of any programs using the deprecated API. Start by reading argparse.h, it's design review of the API that is the most important for those inclined to weigh in.
That maybe brings up one thing: If I'm reading the code correctly, you have to say: int foo;
std::string bar;
ap.arg("-foo %d", &foo);
ap.arg("-bar %s", &bar); Borrowing the int foo;
std::string bar;
Color3f baz;
ap.arg("-foo {}", &foo);
ap.arg("-bar {}", &bar);
ap.arg("-baz {}", &baz); I don't want to derail the review - this already looks like a nice set of changes, just something I had wondered about the old API as well that seems to maybe still be relevant to this new iteration. |
Yeah, it would be nice to eliminate those cues, just say:
and it infers the types from the pointers. Let's say, I'll keep this in mind as a later step. The reason they didn't come along yet is:
But anyway, yeah, this is not the final chapter on ArgParse. I'm sure lots of refinement will come later. |
I've been thinking about overhauling ArgParse for a couple years, and
did most of the work in December when I was home from work. Then sat
on it except for slow burn weekend tinkering, but finally got a chance
to put the final touches on and write the docs this week.
The bottom line is that this is a major rewrite of the APIs for
ArgParse to make them much richer, more flexible, and more closely
resembling those of python's argparse module.
Rather than trying to explain the syntax here, I simply will refer you
to the extensive inline documentation in argparse.h, as well as the
examples in the code base of where it's used.
It sill respects the old syntax, so this change is hoped to not alter
the behavior of any programs using the deprecated API.
Start by reading argparse.h, it's design review of the API that is the
most important for those inclined to weigh in.