def gen_parser(caller, commands, parser, subparsers):
"""
Run setup() for all submodules of sub_commands
:param caller: Module calling this module
:type caller: string
:param commands: Sub-module relative to caller with commands
:type commands: string
:param parser: Argparse object
:type parser: argparse.ArgumentParser
:param subparsers: Subparsers object
:type subparsers: argparse._SubParsersAction
"""
package = importlib.import_module('{}.{}'.format(caller, commands))
for importer, modname, ispkg in \
pkgutil.iter_modules(package.__path__,
prefix='{}.{}.'.format(caller, commands)):
if not ispkg:
found_module = importlib.import_module('{}'.format(modname))
found_module.setup(parser, subparsers)
# vim:et:fdm=marker:sts=4:sw=4:ts=4
评论列表
文章目录