Skip to content

gwmock.cli.repository.list_depositions

gwmock.cli.repository.list_depositions

CLI for managing Zenodo repositories.

gwmock.cli.repository.list_depositions.list_depositions_command(status='published', sandbox=False, token=None)

List depositions for the authenticated user.

Examples:

gwmock repository list gwmock repository list --status draft gwmock repository list --status published --sandbox

Source code in src/gwmock/cli/repository/list_depositions.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def list_depositions_command(
    status: Annotated[
        str, typer.Option("--status", help="Filter by status (draft, published, unsubmitted)")
    ] = "published",
    sandbox: Annotated[bool, typer.Option("--sandbox", help="Use sandbox environment")] = False,
    token: Annotated[str | None, typer.Option("--token", help="Zenodo access token")] = None,
) -> None:
    """List depositions for the authenticated user.

    Examples:
        gwmock repository list
        gwmock repository list --status draft
        gwmock repository list --status published --sandbox
    """
    import logging

    from rich.console import Console
    from rich.table import Table

    from gwmock.cli.repository.utils import get_zenodo_client

    logger = logging.getLogger("gwmock")
    console = Console()

    client = get_zenodo_client(sandbox=sandbox, token=token)

    console.print(f"[bold blue]Listing {status} depositions...[/bold blue]")
    try:
        depositions = client.list_depositions(status=status)

        if not depositions:
            console.print(f"[yellow]No {status} depositions found.[/yellow]")
            return

        table = Table(title=f"{status.capitalize()} Depositions")
        table.add_column("ID", style="cyan", width=12)
        table.add_column("Title", style="green", width=40)
        table.add_column("DOI", style="blue", width=20)
        table.add_column("Created", style="magenta", width=12)

        max_length_of_title = 38
        for dep in depositions:
            dep_id = str(dep.get("id", "N/A"))
            title = dep.get("metadata", {}).get("title", "N/A")
            if len(title) > max_length_of_title:
                title = title[:35] + "..."
            doi = dep.get("doi", "N/A")
            created = dep.get("created", "N/A")[:10]
            table.add_row(dep_id, title, doi, created)

        console.print(table)
    except Exception as e:
        console.print(f"[red]✗ Failed to list depositions: {e}[/red]")
        logger.error("List depositions failed: %s", e)
        raise typer.Exit(1) from e