#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Floyda

import os
import click
from grm import api


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


@cli.command()
@click.argument('params', nargs=-1)
def init(params):
    ''' Create a git remote root directory or reinitialize an existing one. '''
    if len(params) == 0:
        api.init(os.curdir)
    else:
        for path in params:
            api.init(path)


@cli.command()
@click.argument('params', nargs=-1)
def add(params):
    ''' Create a repository. '''
    if len(params) == 0:
        print('Nothing specified, nothing added.')
    else:
        path = os.curdir
        for name in params:
            api.add(path, name)


@cli.command()
@click.argument('params', nargs=-1)
def rm(params):
    ''' Remove a repository. '''
    if len(params) == 0:
        print('Nothing specified, nothing removed.')
    else:
        path = os.curdir
        for name in params:
            api.remove(path, name)


@cli.command()
def list():
    ''' List existing repository. '''
    api.list(os.curdir)


@cli.command()
def migrate():
    ''' Migrate the repositorys to other remote. '''
    click.echo('migrate')


@cli.command()
def config():
    ''' Edit the config.  '''
    api.config(os.curdir)


@cli.command()
def version():
    ''' Show version and exit. '''
    api.version()


if __name__ == '__main__':
    cli()
