Week 15 of 16

Experiment: Your First Typer CLI

Get hands-on with Typer before building the full DVP tool.

Day 72 45 minutes Experiment

Day 72 of 80

Build cli_test.py

Create cli_test.py in your project folder. This is a sandbox — try things, break things, understand how Typer works before committing to the real tool.

cli_test.py — Typer experiments Python
import typer

# Typer() creates a CLI application.
# name= sets the program name in help text.
# help= sets the top-level description.
app = typer.Typer(
    name="dvp-test",
    help="DVP CLI experiments. Try: python cli_test.py --help"
)


@app.command()
def greet(
    # A plain str parameter = required CLI argument
    name: str,
    # typer.Option() = optional --flag with a default
    shout: bool = typer.Option(False, help="SHOUT THE GREETING"),
    times: int = typer.Option(1, help="How many times to greet"),
):
    """Say hello. This docstring becomes the help text for this command."""
    message = f"Hello, {name}!"
    if shout:
        message = message.upper()
    for _ in range(times):
        typer.echo(message)  # typer.echo is like print() but handles special chars better


@app.command()
def platforms(
    filter_by: str = typer.Option(None, "--filter", "-f", help="Filter by keyword"),
):
    """List available AI video platforms."""
    all_platforms = [
        {"name": "Kling", "strength": "Realistic motion, Chinese ecosystem"},
        {"name": "Runway", "strength": "Creative effects, US market"},
        {"name": "Veo", "strength": "Google's model, cinematic quality"},
    ]

    if filter_by:
        all_platforms = [
            p for p in all_platforms
            if filter_by.lower() in p["name"].lower()
            or filter_by.lower() in p["strength"].lower()
        ]

    if not all_platforms:
        typer.echo(f"No platforms matching '{filter_by}'")
        raise typer.Exit(1)  # non-zero exit code = error

    for p in all_platforms:
        typer.echo(f"  {p['name']}: {p['strength']}")


@app.command()
def confirm_demo(
    item: str,
    force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation"),
):
    """Demonstrates typer.confirm() — interactive yes/no prompts."""
    if not force:
        # typer.confirm() shows a y/n prompt and returns True/False
        confirmed = typer.confirm(f"Are you sure you want to delete '{item}'?")
        if not confirmed:
            typer.echo("Cancelled.")
            raise typer.Exit(0)

    typer.echo(f"Deleting {item}... done.")


if __name__ == "__main__":
    app()

Try These Commands

Run each of these and read the output carefully:

Terminal — commands to try bash
# Top-level help — shows all commands
python cli_test.py --help

# Help for a specific command
python cli_test.py greet --help

# Basic usage
python cli_test.py greet Marc

# With options
python cli_test.py greet Marc --shout
python cli_test.py greet Marc --times 3
python cli_test.py greet Marc --shout --times 3

# Short flag alias (-f instead of --filter)
python cli_test.py platforms
python cli_test.py platforms --filter google
python cli_test.py platforms -f creative

# Confirmation prompt
python cli_test.py confirm-demo "my project"
python cli_test.py confirm-demo "my project" --force  # skip prompt
What to Notice

End of Day Checklist

Tomorrow

Days 73–74 build the real dvp.py — a complete CLI tool that wraps all your Prompt Vault functionality.