With #96, tapify() was introduced, which automagically produces and executes the appropriate argparse code based on the type annotations of the passed function:
from tap import tapify
def add(num_1: float, num_2: float) -> float:
print(f'The sum of {num_1} and {num_2} is {num_1 + num_2}.')
if __name__ == '__main__':
tapify(add)
similar to python-fire, tapify should support objects and/or classes, such that subparsers are created for each method. e.g.:
class Calculator(object):
def __init__(self, offset: int = 1):
self._offset = offset
def add(self, x: int, y: int):
print(x + y + self._offset)
def multiply(self, x: int, y: int):
print(x * y + self._offset)
if __name__ == '__main__':
tapify(Calculator, offset=1)
Should produce a main parser with one optional --offset argument and two subparsers (add and multiply) with the appropriate options.
With #96,
tapify()
was introduced, which automagically produces and executes the appropriateargparse
code based on the type annotations of the passed function:similar to python-fire, tapify should support objects and/or classes, such that subparsers are created for each method. e.g.:
Should produce a main parser with one optional
--offset
argument and two subparsers (add
andmultiply
) with the appropriate options.