Skip to content
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

Option parser mixin patterns #23

Open
xkortex opened this issue Oct 29, 2020 · 0 comments
Open

Option parser mixin patterns #23

xkortex opened this issue Oct 29, 2020 · 0 comments

Comments

@xkortex
Copy link

xkortex commented Oct 29, 2020

I've been want for something that lets me reuse flags across multiple subcommand, between projects, etc. The native argparse makes this a little tricky, especially if you want custom pydantic data classes. I have also wanted a click-like ease of experience but without all the decorators and deep stack traces clouding my logs.

I spent a bit of time hacking on the idea and came up with some interesting patterns. There's still a lot to iron out, a lot of the ergonomics could be improved with more introspection, but I thought I would at least throw this over the wall and see if there's any interest in it.

The overall concept is leveraging metaprogramming to create type annotations which double as both type hints and the option parsing metadata. This is by no means the best way of doing it but I think there's promise here in the general idea.

If this doesn't fit with the vibe of this project, I might spin it out into its own thing, but figure I'd check in here and avoid fragmentation if possible. As you mention, argparse's api is a bit thorny, so this tries to sidestep some of that.

This is a suuuuper rough sketch:

https://gist.github.com/xkortex/c59058f9245104d54b4075ef96692554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant