#!/usr/bin/env python3

import click
import os


@click.group()
def cli():
    """A simple CLI tool for scaffolding projects and more."""
    pass


@click.command()
@click.argument('project_name')
def scaffold(project_name):
    """
    Scaffold a new project with the given PROJECT_NAME.
    This will create a directory with the project name and a basic README.md file.
    """
    click.echo(f"Scaffolding project: {project_name}...")
    try:
        # Create the project directory
        os.makedirs(project_name, exist_ok=True)

        # Create a README.md file
        readme_path = os.path.join(project_name, "README.md")
        with open(readme_path, "w") as readme_file:
            readme_file.write(f"# {project_name}\n\nGenerated by the CLI tool.")

        click.echo(click.style(f"Project '{project_name}' scaffolded successfully!", fg="green"))
    except Exception as e:
        click.echo(click.style(f"Error: {e}", fg="red"))


@click.command()
@click.argument('name')
def greet(name):
    """
    Greet a user by NAME.
    """
    click.echo(click.style(f"Hello, {name}! Welcome to the CLI tool.", fg="blue"))


@click.command()
def interactive():
    """
    Run an interactive session to scaffold a project.
    """
    project_name = click.prompt("Enter the project name")
    scaffold(project_name)


# Add commands to the CLI group
cli.add_command(scaffold)
cli.add_command(greet)
cli.add_command(interactive)

if __name__ == "__main__":
    cli()
