#!/usr/bin/env python
import argparse
import logging
import mothermayi.config
import mothermayi.entryway
import mothermayi.hook
import mothermayi.pre_commit
import sys

def main():
    logging.basicConfig()

    parser = argparse.ArgumentParser()
    parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Show more logging information')

    subparsers = parser.add_subparsers()

    parser_install = subparsers.add_parser('install', help='Install the pre-commit hook logic')
    parser_install.set_defaults(func=install)

    parser_run = subparsers.add_parser('pre-commit', help='Run the pre-commit hooks')
    parser_run.set_defaults(func=pre_commit)

    args = parser.parse_args()

    if args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        logging.getLogger().setLevel(logging.WARNING)

    config = mothermayi.config.parse()
    mothermayi.entryway.load()
    sys.exit(args.func(args, config))

def install(args, config):
    return mothermayi.hook.install(config)

def pre_commit(args, config):
    return mothermayi.pre_commit.run(config)

if __name__ == '__main__':
    main()
