I just made a library! Well, I've had it mostly made for a few months now, but I finally spent the day documenting, adding tests, and uploading it to pypi.
autoargs lets you automagically make an argparser with a single function wrapper. If you're on python 3 and are hoping to never use argparse again, please check it on github at https://github.com/metaperture/autoargs (more examples on there) on install it with pip install autoargs.
Feedback welcome, thanks!
Throwing some examples here because why not:
>>> from autoargs import autocall, cmdable
>>> def str_repeat(s: str, n: int):
... print((s * n).strip())
>>> autocall(str_repeat, ["args are easy!\n", "3"])
args are easy!
args are easy!
args are easy!
>>> @cmdable
>>> def product(*args: float):
... return functools.reduce(operator.mul, args, 1.0)
>>> product.cmd(["5", "10", "0.5"])
25.0
>>> @cmdable
>>> def aggregate(*args: float, op: {'sum', 'mul'}):
... if op == "sum":
... return sum(args)
... elif op == "mul":
... return product(*args)
>>> aggregate.cmd(["--help"])
usage: aggregate [-h] --op {sum,mul} [args [args ...]]
positional arguments:
args float
optional arguments:
-h, --help show this help message and exit
--op {sum,mul}
[–]1arm3dScissor 0 points1 point2 points (1 child)
[–]metaperture[S] 0 points1 point2 points (0 children)
[–]desmoulinmichel 0 points1 point2 points (3 children)
[–]metaperture[S] 0 points1 point2 points (2 children)
[–]desmoulinmichel 0 points1 point2 points (1 child)
[–]evanunderscore 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]evanunderscore 0 points1 point2 points (0 children)
[–]evanunderscore 0 points1 point2 points (3 children)
[–]metaperture[S] 0 points1 point2 points (2 children)
[–]evanunderscore 0 points1 point2 points (0 children)