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).
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
**kwargson 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.argon the outer function, but that's not very DRY. I've taken to writing a hacky decorator that calls_get_args_from_signatureon both the outer function and the inner function and also callsget_arg_specon 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_signatureand returns a dict of dicts mapping real argument names to dict representations (with the appropriate auto-generated option strings).