#!/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 of the koji module of flr """

import click

import flr.koji

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

@click.command()
@click.argument('branch', nargs=1)
@click.argument('anames', nargs=-1)
@click.option('--build-type', help="Koji build type (rpm, container, etc)", default="rpm")
@click.option('--user', help="Fedora Account System username (defaults to local username)", default=None)
@click.option('--stage/--prod', help="Perform these actions in stage/prod infrastructure (Default: --prod)", default=False)
def rebuild(branch, anames, build_type, user, stage):
    """
    copy an image from a source registry repo to a destination registry repo

    Usage: flr-docker rebuild BRANCH ANAME [ANAME ANAME ...] [--build-type]
                                           [--stage] [--prod]

        \b
        BRANCH  - DistGit branch to perform the operation on
        ANAME   - One or more (space delimited) artifacts as they are named in
                  koji (rpm/container name)

    OPTIONS:
        --build-type  - Koji build type (default 'rpm')
        --stage       - Use stage infrastructure
        --prod        - Use prod infrastructure (this is the default, opt can
                        be omitted)
        --user        - Fedora Account System username to use (will default to
                        $USER host env variable)
    """

    if anames and branch:
        flr.koji.rebuild(build_type, branch, anames, user=user, stage=stage)
    else:
        flr.log.error("BRANCH and ANAME must be provided for 'flr-koji rebuild'")

cli.add_command(rebuild)

if __name__ == '__main__':
    cli()


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