import sys

import click

from .utils import write_to_file, get_problem
from .types import ProblemType


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


@click.command()
@click.option('--path', '-p', type=click.Path())
@click.option('--overwrite', '-o', is_flag=True)
@click.argument('problem', type=ProblemType())
@click.argument('language', required=False, default='python')
def generate(problem, language, path, overwrite):
    try:
        path, success = write_to_file(problem, language, path, overwrite)
    except (FileNotFoundError, PermissionError) as e:
        sys.exit('An exception occurred: %s' % e)

    if not success:
        sys.exit('%s already exists. Use the --overwrite flag to overwrite it' %
                 click.format_filename(path))

    click.echo('Written to %s' % click.format_filename(path))

commands.add_command(generate)

@@ -102,35 +102,44 @@
 e%0A%0A%0A
-@
+commands = 
 click.
-g
+G
 roup()%0A
-def 
+%0A%0A@
 commands
 ():%0A
@@ -138,29 +138,8 @@
 ands
-():%0A    pass%0A%0A%0A@click
 .com
@@ -805,35 +805,4 @@
 ))%0A%0A
-commands.add_command(generate)%0A

Simplify command grouping