""" generator script scaffolding """

import argparse
import logging
import sys

from . import options, render


def _parse(tags):
    parser = argparse.ArgumentParser()
    for opt in options.get(tags):
        opt.add_to(parser)
    ret = parser.parse_args()
    log_level = logging.DEBUG if ret.verbose else logging.INFO
    logging.basicConfig(format="{levelname} {message}", style='{', level=log_level)
    return ret


def run(*modules):
    """ run generation functions in specified in `modules`, or in current module by default
    """
    if modules:
        opts = _parse({t for m in modules for t in m.tags})
        for m in modules:
            m.generate(opts, render.Renderer())
    else:
        run(sys.modules["__main__"])

""" generator script scaffolding """

import argparse
import logging
import sys
from typing import Set

from . import options, render


def _parse(tags: Set[str]) -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    for opt in options.get(tags):
        opt.add_to(parser)
    return parser.parse_args()


def run(*modules, **kwargs):
    """ run generation functions in specified in `modules`, or in current module by default
    """
    if modules:
        if kwargs:
            opts = argparse.Namespace(**kwargs)
        else:
            opts = _parse({t for m in modules for t in m.tags})
        log_level = logging.DEBUG if opts.verbose else logging.INFO
        logging.basicConfig(format="{levelname} {message}", style='{', level=log_level)
        for m in modules:
            m.generate(opts, render.Renderer())
    else:
        run(sys.modules["__main__"], **kwargs)

make generator.run accept options