#!python

import argparse
from ucopy import ucopy

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("source", nargs='+', help="source directory or glob path")
    parser.add_argument("dest", help="destination directory", type=str)
    parser.add_argument("-e", "--extensions", type=str, default='*',
                        help="comma-separated allowed extensions")
    parser.add_argument("-x", "--exclude", type=str, default='',
                        help="comma-separated excluded extensions (override allowed)")
    parser.add_argument("-v", "--verbose", action='store_true')
    try:
        args = parser.parse_args()
    except:
        print(""" 
            Union copier - copy files from one directory to another with force unique  suffix, 
            if target directory already contains a file with the same name
            Source path may contains glob pattern
            Usage:   ucopy sourcepath  destpath  [-e allowed_extensions] or [-x excluded_extensions] [-v|--verbose]

            Example1: copy only png files, show progress log 
               ucopy /src/path/ /dest/path/ -e png --verbose

            Example2: copy files with extensions .png .jpg .txt
               ucopy /src/path/ /dest/path/ -e png,jpg,txt

            Example3: copy all files, but exclude ones with .zip and .gz extensions
               ucopy /src/path/ /dest/path/ -x zip,gz

            Example4: copy all files without restriction (by default)
               ucopy /src/path/ /dest/path/ -e *

            Example5: copy from multiple source directories matched by glob pattern
                ucopy /src/path/*/some/*/ /dest/path/ 
            """)
        exit(1)
    is_success = ucopy.run(args.source, args.dest, args.extensions, args.exclude, args.verbose)
    exit(0 if is_success else 1)