#!/usr/bin/env python

"""snap-diff is an extra tool used to test python-snapdiff functions or
provide as a command line tool"""

import argparse
import sys

import snapdiff


def main(argv):
    """The main body"""
    description = 'Diff two repos with different urls'
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(dest='old', help='old repo')
    parser.add_argument(dest='new', help='new repo')
    parser.add_argument('-t', dest='type', default='repo', \
            choices=['repo', 'image'], \
            help="which diff you want(default is 'repo')")
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--json', help='output json diff', action='store_true')
    group.add_argument('-d', dest='directory', \
            help='output html diff into directory')
    parser.add_argument('-n', dest='name', \
            help="give a name to diff html(effective to '-d' option only)")
    args = parser.parse_args(argv)

    if args.directory and args.name:
        snapdiff.diff_to_dist(args.old, args.new, args.directory, \
                style=args.type, diff_name=args.name)
    elif args.directory:
        snapdiff.diff_to_dist(args.old, args.new, args.directory, \
                style=args.type)
    elif args.json:
        print snapdiff.diff_to_json(args.old, args.new, style=args.type)
    else:
        print snapdiff.diff_to_html(args.old, args.new, style=args.type)

if __name__ == '__main__':
    try:
        sys.exit(main(sys.argv[1:]))
    except KeyboardInterrupt:
        pass
