Export the current graph to a portable .cgc bundle. Creates a pre-indexed graph snapshot that can be distributed and loaded instantly without re-indexing. Perfect for sharing famous repositories. Examples: cgc bundle export numpy.cgc --repo /path/to/numpy c
(
output: str = typer.Argument(..., help="Output path for the .cgc bundle file"),
repo: Optional[str] = typer.Option(None, "--repo", "-r", help="Specific repository path to export (default: export all)"),
no_stats: bool = typer.Option(False, "--no-stats", help="Skip statistics generation"),
context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
)
| 609 | |
| 610 | @bundle_app.command("export") |
| 611 | def bundle_export( |
| 612 | output: str = typer.Argument(..., help="Output path for the .cgc bundle file"), |
| 613 | repo: Optional[str] = typer.Option(None, "--repo", "-r", help="Specific repository path to export (default: export all)"), |
| 614 | no_stats: bool = typer.Option(False, "--no-stats", help="Skip statistics generation"), |
| 615 | context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"), |
| 616 | ): |
| 617 | """ |
| 618 | Export the current graph to a portable .cgc bundle. |
| 619 | |
| 620 | Creates a pre-indexed graph snapshot that can be distributed and loaded |
| 621 | instantly without re-indexing. Perfect for sharing famous repositories. |
| 622 | |
| 623 | Examples: |
| 624 | cgc bundle export numpy.cgc --repo /path/to/numpy |
| 625 | cgc bundle export my-project.cgc |
| 626 | cgc bundle export all-repos.cgc --no-stats |
| 627 | """ |
| 628 | _load_credentials() |
| 629 | from codegraphcontext.core.cgc_bundle import CGCBundle |
| 630 | |
| 631 | services = _initialize_services(context) |
| 632 | if not all(services[:3]): |
| 633 | raise typer.Exit(code=1) |
| 634 | db_manager, _, code_finder = services[:3] |
| 635 | |
| 636 | try: |
| 637 | output_path = Path(output) |
| 638 | repo_path = Path(repo).resolve() if repo else None |
| 639 | |
| 640 | console.print(f"[cyan]Exporting graph to {output_path}...[/cyan]") |
| 641 | if repo_path: |
| 642 | console.print(f"[dim]Repository: {repo_path}[/dim]") |
| 643 | else: |
| 644 | console.print("[dim]Exporting all repositories[/dim]") |
| 645 | |
| 646 | bundle = CGCBundle(db_manager) |
| 647 | success, message = bundle.export_to_bundle( |
| 648 | output_path, |
| 649 | repo_path=repo_path, |
| 650 | include_stats=not no_stats |
| 651 | ) |
| 652 | |
| 653 | if success: |
| 654 | console.print(f"[bold green]{message}[/bold green]") |
| 655 | else: |
| 656 | console.print(f"[bold red]Export failed: {message}[/bold red]") |
| 657 | raise typer.Exit(code=1) |
| 658 | |
| 659 | finally: |
| 660 | db_manager.close_driver() |
| 661 | |
| 662 | def _confirm_bundle_clear(clear: bool, yes: bool) -> bool: |
| 663 | """Return True if import may proceed; False if user cancelled.""" |
no test coverage detected