Skip to content

Ability to grab arguments from more than one function #103

Description

@dwf

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).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions