#!/usr/bin/python

import os

from argparse import ArgumentParser
from getoverhere.downloader import getDownloader



def main():
    parser = ArgumentParser()
    parser.add_argument('path',
                        help='Target path on disk.')
    parser.add_argument('deployments', nargs='*', help='Deployments.')
    parser.add_argument('-fi', '--full-install',
                        help='Overwrite all files.',
                        action='store_true')
    parser.add_argument('-sc', '--skip-confirm',
                        help='Skip confirmation for downloading files.',
                        action='store_true')
    parser.add_argument('-fu', '--force-update',
                        help='Force install if already up-to-date. '
                             'This should not be needed unless something went horribly wrong.',
                        action='store_true')
    parser.add_argument('-afi', '--allow-full-install',
                        help='If no previous installation could be found for this path, perform a full install.',
                        action='store_true')
    parser.add_argument('-v', '--verbose',
                        help='Output all status messages.',
                        action='store_true')
    args = parser.parse_args()

    path = os.path.abspath(os.path.normpath(args.path))
    allow_full_install = args.allow_full_install
    full_install = args.full_install
    skip_confirm = args.skip_confirm
    force_update = args.force_update
    verbose = args.verbose

    for deployment in args.deployments:
        downloader = getDownloader(deployment, path, full_install,
                                   allow_full_install, skip_confirm,
                                   force_update, verbose)
        if downloader is None:
            print('[getoverhere] No downloader found for \'%s\'.' % deployment)
        else:
            downloader.download()



if __name__ == '__main__':
    main()
