Load a pre-indexed bundle (download if needed, then import). This is a convenience command that will: 1. Check if the bundle exists locally 2. Download from registry if not found 3. Import the bundle into the database Examples: cgc load numpy cgc lo
(
bundle_name: str = typer.Argument(..., help="Bundle name or path to load (e.g., 'numpy' or 'numpy.cgc')"),
clear: bool = typer.Option(False, "--clear", help="Clear existing graph data before loading")
)
| 670 | |
| 671 | @bundle_app.command("load") |
| 672 | def bundle_load( |
| 673 | bundle_name: str = typer.Argument(..., help="Bundle name or path to load (e.g., 'numpy' or 'numpy.cgc')"), |
| 674 | clear: bool = typer.Option(False, "--clear", help="Clear existing graph data before loading") |
| 675 | ): |
| 676 | """ |
| 677 | Load a pre-indexed bundle (download if needed, then import). |
| 678 | |
| 679 | This is a convenience command that will: |
| 680 | 1. Check if the bundle exists locally |
| 681 | 2. Download from registry if not found |
| 682 | 3. Import the bundle into the database |
| 683 | |
| 684 | Examples: |
| 685 | cgc load numpy |
| 686 | cgc load numpy.cgc --clear |
| 687 | cgc load /path/to/bundle.cgc |
| 688 | """ |
| 689 | _load_credentials() |
| 690 | |
| 691 | bundle_path = Path(bundle_name) |
| 692 | |
| 693 | # If it's an absolute path or has .cgc extension and exists, use it directly |
| 694 | if bundle_path.is_absolute() or (bundle_path.suffix == '.cgc' and bundle_path.exists()): |
| 695 | bundle_import(str(bundle_path), clear=clear) |
| 696 | return |
| 697 | |
| 698 | # Add .cgc extension if not present |
| 699 | if not bundle_path.suffix: |
| 700 | bundle_path = Path(f"{bundle_name}.cgc") |
| 701 | |
| 702 | # Check if exists locally |
| 703 | if bundle_path.exists(): |
| 704 | console.print(f"[dim]Found local bundle: {bundle_path}[/dim]") |
| 705 | bundle_import(str(bundle_path), clear=clear) |
| 706 | return |
| 707 | |
| 708 | # Try to download from registry |
| 709 | console.print(f"[yellow]Bundle '{bundle_name}' not found locally.[/yellow]") |
| 710 | console.print(f"[cyan]Attempting to download from registry...[/cyan]") |
| 711 | |
| 712 | try: |
| 713 | from .registry_commands import download_bundle |
| 714 | |
| 715 | # Extract just the name (without .cgc extension) |
| 716 | name = bundle_path.stem |
| 717 | |
| 718 | # Download the bundle |
| 719 | downloaded_path = download_bundle(name, output_dir=None, auto_load=True) |
| 720 | |
| 721 | if downloaded_path: |
| 722 | # Import the downloaded bundle |
| 723 | bundle_import(downloaded_path, clear=clear) |
| 724 | else: |
| 725 | console.print(f"[bold red]Failed to download bundle '{name}'[/bold red]") |
| 726 | raise typer.Exit(code=1) |
| 727 | |
| 728 | except Exception as e: |
| 729 | console.print(f"[bold red]Error: {e}[/bold red]") |
no test coverage detected