fromtypingimportOptionalfromargerimportArgerfromtests.utilsimport_reprintctx={}@Arger.init(prog="pytest")# any argument to the parserdefarger(verbose=False,log=False,log_file:Optional[str]=None):"""App Description goes here. :param verbose: verbose output :param log_file: name of the log file to write output """ctx.update(**locals())container=[]@arger.add_cmddefcreate(name:str):"""Create new test. :param name: Name of the test """container.append(container)_reprint(**locals(),**ctx)@arger.add_cmddefremove(name:str):"""Remove a test. :param name: Name of the test """ifremoveincontainer:container.remove(remove)_reprint(**locals(),**ctx)@arger.add_cmddeflist(filter:Optional[str]):"""List all tests."""_reprint(**locals(),container=container,**ctx)if__name__=="__main__":arger.run()
The functions are converted to sub-commands while the function arger serves as the entrypoint.
It will get executed before other sub-commands.