#!python

import click
from requests import get

class styles:
    end = '\033[0m'
    red = '\033[31m'

def get_ignore(language):
    body = get('https://raw.githubusercontent.com/github/gitignore/master/{}.gitignore'.format(language))
    if body.status_code == 404:
        body = get('https://raw.githubusercontent.com/github/gitignore/master/{}.gitignore'.format(language.capitalize()))
    if body.status_code == 404:
        click.echo('{}Language not found, check capitalization{}'.format(styles.red, styles.end))
        exit()
    return(body.text)

@click.group()
def ignore():
    'Create gitignore templates from your command line'

@ignore.command()
@click.argument('language', required=True)
@click.argument('directory', required=False, default='.')
def new(language, directory):
    'Create a gitignore file with a template'
    body = get_ignore(language)
    directory = directory + '/'
    open('{}.gitignore'.format(directory), 'w+').write(body)

@ignore.command()
@click.argument('language', required=True)
def show(language):
    'Display a sample gitignore file'
    click.echo(get_ignore(language))

ignore(prog_name='ignore')