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

Ability to grab arguments from more than one function #103

Open
dwf opened this issue Jun 20, 2016 · 0 comments
Open

Ability to grab arguments from more than one function #103

dwf opened this issue Jun 20, 2016 · 0 comments

Comments

@dwf
Copy link
Contributor

dwf commented Jun 20, 2016

First, thanks for the wonderful package.

I am often writing lots of scripts/commands that do slightly different things, but with some shared logic at the end. I implement this by writing one function that handles the common stuff, and a bunch that all call it as their last line. I declare arguments for the inner function and, in the spirit of DRY, have **kwargs on the outer function for any configuration that just gets passed through.

argh handles this nicely if I explicitly declare the inner function's parameters via @argh.arg on the outer function, but that's not very DRY. I've taken to writing a hacky decorator that calls _get_args_from_signature on both the outer function and the inner function and also calls get_arg_spec on each. It grabs any argh-declared arguments from the inner function and takes them as-is, and also appends any keyword arguments from the inner function that don't conflict with those defined by the outer function.

The way I do this right now involves calling a private function (_get_args_from_signature) and inferring the destination. Even without full support for this use case, modifications to argh could definitely make this less painful. I think the obvious one would be a public utility function that replaces _get_args_from_signature and returns a dict of dicts mapping real argument names to dict representations (with the appropriate auto-generated option strings).

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

No branches or pull requests

2 participants