#! /usr/bin/env python

import argparse

from commands import changes, settings, upstream


def main():

    parser = argparse.ArgumentParser(
        prog='git changes',
        version='git-changes 0.4.0',
        description=changes.__doc__,
        epilog='for more detail, use: git help changes'
    )

    # -b|--branch
    default_branch = settings.get('git-changes.default-branch', default='master')
    branch_group = parser.add_mutually_exclusive_group()
    branch_group.add_argument(
        '-b',
        '--branch',
        help='show the commits between HEAD and <branch>',
        metavar='<branch>',
        default=default_branch
    )

    # -r|--remote
    branch_group.add_argument(
        '-r',
        '--remote',
        help='show the commits between the local and remote head',
        action='store_const',
        const=upstream.upstream(True),
        dest='branch'
    )

    # details
    details_group = parser.add_mutually_exclusive_group()
    details_group.add_argument(
        '-c',
        '--count',
        help='show as a count of changes',
        action='store_const',
        const='count',
        dest='details'
    )
    details_group.add_argument(
        '-s',
        '--stat',
        help='show as a diffstat',
        action='store_const',
        const='stat',
        dest='details'
    )
    details_group.add_argument(
        '-d',
        '--diff',
        help='show as a full diff',
        action='store_const',
        const='diff',
        dest='details'
    )

    # color
    color_group = parser.add_mutually_exclusive_group()
    color_group.add_argument(
        '--color',
        help='always color output',
        const='always',
        dest='color_when',
        nargs='?',
        choices=('always', 'never', 'auto'),
        default=settings.get('color.ui', default='auto')
    )
    color_group.add_argument(
        '--no-color',
        help='never color output',
        action='store_const',
        const='never',
        dest='color_when'
    )

    changes.changes(**vars(parser.parse_args()))

if __name__ == '__main__':
    main()
