#!/usr/bin/env python3

import sys
import argparse
import sugar.lib.exceptions
from sugarsdk.modval import ModuleValidator

__version__ = "0.0.1 Alpha"


def main():
    """
    Main function.

    :return:
    """
    parser = argparse.ArgumentParser(description="Sugar Module Validator, {}".format(__version__))
    parser.add_argument("-t", "--type", help="Type of the module.", choices=["runner", "state"])
    parser.add_argument("-n", "--name", help="Name of the module with the namespace. Example: 'foo.bar.mymodule'.")
    parser.add_argument("-a", "--all", help="Validate all modules (runners and state).", action="store_true")
    args = parser.parse_args()

    try:
        modgen = ModuleValidator(args)
        if not modgen.validate():
            parser.print_help()
        else:
            sys.exit(modgen.report())
    except sugar.lib.exceptions.SugarException as exc:
        parser.print_usage()
        print("\n{}\n".format(exc))


if __name__ == "__main__":
    main()
