typed-argument-parser icon indicating copy to clipboard operation
typed-argument-parser copied to clipboard

Refactor `tapify` to enable subparsers

Open swansonk14 opened this issue 2 years ago • 1 comments

One important use case from Tap/tapify that is missing is the ability to create a subparser that can parse arguments for different functions depending on which subparser is called. This is made difficult because tapify both instantiates a Tap class and runs the function without exposing the Tap class, which is needed for subparsing. We propose to refactor tapify by first creating a function called convert_to_tap that takes a function and dynamically creates a Tap subclass definition with the arguments of that function. In tapify, this Tap class can be instantiated and used to parse arguments and run the function. This Tap class can also be used explicitly or can be used as a subparser. Please see a potential implementation here: https://github.com/swansonk14/chemfunc/blob/main/chemfunc/utils.py#L13

swansonk14 avatar Jun 13 '23 03:06 swansonk14

Ensure that the arguments in the help string are in the same order as they are in the function.

swansonk14 avatar Jun 25 '23 00:06 swansonk14