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"),
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation when using --clear"),
)
| 732 | |
| 733 | @bundle_app.command("load") |
| 734 | def bundle_load( |
| 735 | bundle_name: str = typer.Argument(..., help="Bundle name or path to load (e.g., 'numpy' or 'numpy.cgc')"), |
| 736 | clear: bool = typer.Option(False, "--clear", help="Clear existing graph data before loading"), |
| 737 | yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation when using --clear"), |
| 738 | ): |
| 739 | """ |
| 740 | Load a pre-indexed bundle (download if needed, then import). |
| 741 | |
| 742 | This is a convenience command that will: |
| 743 | 1. Check if the bundle exists locally |
| 744 | 2. Download from registry if not found |
| 745 | 3. Import the bundle into the database |
| 746 | |
| 747 | Examples: |
| 748 | cgc load numpy |
| 749 | cgc load numpy.cgc --clear |
| 750 | cgc load /path/to/bundle.cgc |
| 751 | """ |
| 752 | _load_credentials() |
| 753 | |
| 754 | bundle_path = Path(bundle_name) |
| 755 | |
| 756 | # If it's an absolute path or has .cgc extension and exists, use it directly |
| 757 | if bundle_path.is_absolute() or (bundle_path.suffix == '.cgc' and bundle_path.exists()): |
| 758 | bundle_import(str(bundle_path), clear=clear, yes=yes) |
| 759 | return |
| 760 | |
| 761 | # Add .cgc extension if not present |
| 762 | if not bundle_path.suffix: |
| 763 | bundle_path = Path(f"{bundle_name}.cgc") |
| 764 | |
| 765 | # Check if exists locally |
| 766 | if bundle_path.exists(): |
| 767 | console.print(f"[dim]Found local bundle: {bundle_path}[/dim]") |
| 768 | bundle_import(str(bundle_path), clear=clear, yes=yes) |
| 769 | return |
| 770 | |
| 771 | # Try to download from registry |
| 772 | console.print(f"[yellow]Bundle '{bundle_name}' not found locally.[/yellow]") |
| 773 | console.print("[cyan]Attempting to download from registry...[/cyan]") |
| 774 | |
| 775 | try: |
| 776 | from .registry_commands import download_bundle |
| 777 | |
| 778 | # Extract just the name (without .cgc extension) |
| 779 | name = bundle_path.stem |
| 780 | |
| 781 | # Download the bundle |
| 782 | downloaded_path = download_bundle(name, output_dir=None, auto_load=True) |
| 783 | |
| 784 | if downloaded_path: |
| 785 | # Import the downloaded bundle |
| 786 | bundle_import(downloaded_path, clear=clear, yes=yes) |
| 787 | else: |
| 788 | console.print(f"[bold red]Failed to download bundle '{name}'[/bold red]") |
| 789 | raise typer.Exit(code=1) |
| 790 | |
| 791 | except Exception as e: |
no test coverage detected