Spaces:
Sleeping

File size: 3,027 Bytes
7c87115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Alias CLI commands."""

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

from notebooklm_tools.core.alias import get_alias_manager, detect_id_type

console = Console()
app = typer.Typer(
    help="Manage ID aliases",
    rich_markup_mode="rich",
    no_args_is_help=True,
)


@app.command("set")
def set_alias(
    name: str = typer.Argument(..., help="Alias name (e.g. 'my-notebook')"),
    value: str = typer.Argument(..., help="ID value (e.g. valid UUID)"),
    alias_type: str = typer.Option(
        None, "--type", "-t",
        help="Type: notebook, source, artifact, task (auto-detected if not specified)",
    ),
    profile: str = typer.Option(None, "--profile", "-p", help="Profile to use for detection"),
) -> None:
    """Create or update an alias for an ID."""
    manager = get_alias_manager()
    
    # Auto-detect type if not provided
    if not alias_type:
        with console.status("[dim]Detecting ID type...[/dim]"):
            alias_type = detect_id_type(value, profile)
    
    manager.set_alias(name, value, alias_type)
    
    type_display = f"[dim]({alias_type})[/dim]" if alias_type != "unknown" else ""
    console.print(f"[green]βœ“[/green] Alias set: [bold]{name}[/bold] -> {value} {type_display}")


@app.command("get")
def get_alias(
    name: str = typer.Argument(..., help="Alias name"),
) -> None:
    """Get the value of an alias."""
    manager = get_alias_manager()
    entry = manager.get_entry(name)
    
    if entry:
        console.print(entry.value)
    else:
        console.print(f"[red]Error:[/red] Alias '{name}' not found")
        raise typer.Exit(1)


@app.command("list")
def list_aliases() -> None:
    """List all aliases."""
    manager = get_alias_manager()
    aliases = manager.list_aliases()
    
    if not aliases:
        console.print("No aliases defined.")
        return

    table = Table(title="Aliases")
    table.add_column("Name", style="cyan")
    table.add_column("Type", style="magenta")
    table.add_column("Value", style="green")
    
    # Type icons for visual distinction
    type_icons = {
        "notebook": "πŸ““",
        "source": "πŸ“„",
        "artifact": "🎨",
        "task": "πŸ”",
        "unknown": "❓",
    }
    
    for name, entry in sorted(aliases.items()):
        icon = type_icons.get(entry.type, "❓")
        table.add_row(name, f"{icon} {entry.type}", entry.value)
    
    console.print(table)


@app.command("delete")
def delete_alias(
    name: str = typer.Argument(..., help="Alias name"),
    confirm: bool = typer.Option(False, "--confirm", "-y", help="Skip confirmation"),
) -> None:
    """Delete an alias."""
    if not confirm:
        typer.confirm(f"Are you sure you want to delete alias '{name}'?", abort=True)
        
    manager = get_alias_manager()
    if manager.delete_alias(name):
        console.print(f"[green]βœ“[/green] Deleted alias: {name}")
    else:
        console.print(f"[yellow]⚠[/yellow] Alias '{name}' not found")
        raise typer.Exit(1)