You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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 callsget_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).The text was updated successfully, but these errors were encountered: