Skip to content

tux.cli

Command-line interface for Tux development tools.

This module provides a modern command-line interface using Click.

Modules:

Name Description
core

Core CLI functionality for Tux.

database

Database commands for the Tux CLI.

dev

Development tools and utilities for Tux.

docker

Docker commands for the Tux CLI.

docs

Documentation commands for the Tux CLI.

ui

Terminal UI utilities for the CLI.

Functions:

Name Description
cli

Tux CLI

main

Entry point for the CLI.

Functions

cli(ctx: Context) -> None

Tux CLI

Source code in tux/cli/core.py
Python
@click.group(cls=GlobalOptionGroup)
@click.version_option(version=__version__, prog_name="Tux")  # type: ignore[misc]
@click.pass_context
def cli(ctx: Context) -> None:  # Remove env_dev and env_prod params
    """Tux CLI"""

    # Initialize context object
    ctx.ensure_object(dict)  # Still useful for subcommands if they use ctx.obj
    ctx.meta.setdefault("is_dev", True)  # Ensure 'is_dev' exists even if parse_args wasn't fully run (e.g., --help)

    # Retrieve the environment mode set by GlobalOptionGroup.parse_args
    is_dev = ctx.meta["is_dev"]
    configure_environment(dev_mode=is_dev)

    # Conditionally set DATABASE_URL for commands that require it
    invoked_command = ctx.invoked_subcommand

    if invoked_command is not None and invoked_command not in NO_DB_COMMANDS:
        logger.trace(f"Command '{invoked_command}' may require database access. Setting DATABASE_URL.")
        try:
            db_url = get_database_url()
            os.environ["DATABASE_URL"] = db_url
            logger.trace("Set DATABASE_URL environment variable for Prisma.")
        except Exception as e:
            # Log critical error and exit if URL couldn't be determined for a required command.
            logger.critical(f"Command '{invoked_command}' requires a database, but failed to configure URL: {e}")
            logger.critical("Ensure DEV_DATABASE_URL or PROD_DATABASE_URL is set in your .env file or environment.")
            sys.exit(1)  # Exit with a non-zero status code
    elif invoked_command:
        logger.trace(f"Command '{invoked_command}' does not require database access. Skipping DATABASE_URL setup.")

main() -> int

Entry point for the CLI.

Source code in tux/cli/core.py
Python
def main() -> int:
    """Entry point for the CLI."""

    # Configure logging first!
    setup_logging()

    # No need for default env config here, handled by @cli options
    # register_commands()

    # Run the CLI
    # Click will parse global options, call cli func, then subcommand func
    # We need to ensure commands are registered before cli() is called.
    register_commands()
    return cli() or 0  # Return 0 if cli() returns None