Source code for dbx_python_cli.commands.list

"""List command for listing repositories."""

import json

import typer

from dbx_python_cli.utils.repo import get_base_dir, get_config, list_repos

# Create a Typer app that will act as a single command
app = typer.Typer(
    help="List repositories",
    no_args_is_help=False,
    invoke_without_command=True,
    context_settings={
        "allow_interspersed_args": False,
        "help_option_names": ["-h", "--help"],
    },
)


[docs] @app.callback() def list_callback( ctx: typer.Context, ): """List all repositories (cloned and available). Shows a tree view of all repository groups with status indicators: - ✓ = cloned - ○ = available to clone - ? = cloned but not in config Examples:: dbx list # List all repositories """ # Get verbose flag from parent context verbose = ctx.obj.get("verbose", False) if ctx.obj else False try: config = get_config() base_dir = get_base_dir(config) if verbose: typer.echo(f"[verbose] Using base directory: {base_dir}") typer.echo(f"[verbose] Config:\n{json.dumps(config, indent=4)}\n") except Exception as e: typer.echo(f"❌ Error: {e}", err=True) raise typer.Exit(1) formatted_output = list_repos(base_dir, config=config) if not formatted_output: typer.echo(f"Base directory: {base_dir}\n") typer.echo("No repositories found.") typer.echo("\nClone repositories using: dbx clone -g <group>") return typer.echo(f"{typer.style('Base directory:', bold=True)} {base_dir}\n") typer.echo(f"{typer.style('Repository status:', bold=True)}\n") typer.echo(formatted_output) cloned_label = typer.style("✓", fg=typer.colors.GREEN) available_label = typer.style("○", fg=typer.colors.YELLOW) unknown_label = typer.style("?", fg=typer.colors.MAGENTA) typer.echo( f"\nLegend: {cloned_label} = cloned, {available_label} = available to clone, {unknown_label} = cloned but not in config" )