#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

""" cli util to expose the docker components of the container module of flr """

import click

import flr.dkr

@click.group()
def cli():
    pass

@click.command()
@click.argument('srcimg')
@click.argument('destimg')
@click.option('--daemon', help="Docker daemon URI", default=None)
@click.option('--registry', help="Docker registry URI to login to", default=None)
@click.option('--username', help="Username to login as to provided registry", default=None)
def remote_copy(srcimg, destimg, daemon, registry, username):
    """
    copy an image from a source registry repo to a destination registry repo

    Usage: flr-docker remote-copy SRCIMG DESTIMG

        \b
        SRCIMG  - Source Docker Image URI
        DESTIMG - Destination Docker Image URI

    This utility exposes flr.dkr.remote_copy() to the cli
    """

    if daemon:
        clientargs = {"base_url": daemon}
    else:
        clientargs = {}

    flr.dkr.remote_copy(
        srcimg,
        destimg,
        client_args=clientargs,
        registry=registry,
        username=username
    )

@click.command()
@click.argument('imagename')
def remove_image(imagename):
    """
    Remove a local docker image

    Usage: flr-docker remove-image IMAGENAME

        \b
        IMAGENAME - Local Docker Image Name to remove

    This utility exposes flr.dkr.remove_image() to the cli
    """

    flr.dkr.remove_image(imagename)

cli.add_command(remote_copy, name="remote-copy")
cli.add_command(remove_image, name="remove-image")

if __name__ == '__main__':
    cli()

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
