|
| 1 | +import shutil |
| 2 | +from pathlib import Path |
| 3 | +import typer |
| 4 | +from rich.console import Console |
| 5 | + |
| 6 | +app = typer.Typer() |
| 7 | +console = Console() |
| 8 | + |
| 9 | +@app.command() |
| 10 | +def onixs( |
| 11 | + sdk_path: Path = typer.Argument(..., exists=True, file_okay=False, dir_okay=True, help="Path to the OnixS SDK root directory"), |
| 12 | + dry_run: bool = typer.Option(False, "--dry-run", help="Simulate the injection without moving files") |
| 13 | +): |
| 14 | + """ |
| 15 | + Inject the OnixS C++ SDK into the QuanuX extension. |
| 16 | + """ |
| 17 | + detect_and_integrate(sdk_path, "onixs", "include/OnixS/FixEngine.h", dry_run) |
| 18 | + |
| 19 | +def detect_and_integrate(sdk_path: Path, ext_name: str, marker_file: str, dry_run: bool): |
| 20 | + sdk_path = sdk_path.resolve() |
| 21 | + console.print(f"🔍 Analyzing SDK at: [bold]{sdk_path}[/bold]") |
| 22 | + |
| 23 | + if (sdk_path / marker_file).exists(): |
| 24 | + console.print(f"✅ Detected verified SDK for: [green]{ext_name}[/green]") |
| 25 | + else: |
| 26 | + console.print(f"❌ [red]Error:[/red] Could not find '{marker_file}' in the provided SDK path.") |
| 27 | + raise typer.Exit(code=1) |
| 28 | + |
| 29 | + # Calculate repo root (assuming this file is in server/cli/src/quanuxctl/commands) |
| 30 | + # Adjustment: logic depends on where this file effectively sits. |
| 31 | + # Current: server/cli/src/quanuxctl/commands/integrate.py |
| 32 | + # Root is up 5 levels? |
| 33 | + # Let's use a safer relative lookup if possible, or assume CWD is project root if run via python -m |
| 34 | + |
| 35 | + # Heuristic: Look for 'extensions' dir in parents |
| 36 | + repo_root = None |
| 37 | + for parent in Path(__file__).parents: |
| 38 | + if (parent / "extensions").exists(): |
| 39 | + repo_root = parent |
| 40 | + break |
| 41 | + |
| 42 | + if not repo_root: |
| 43 | + console.print("❌ [red]Error:[/red] Could not locate QuanuX repository root.") |
| 44 | + raise typer.Exit(code=1) |
| 45 | + |
| 46 | + dest_dir = repo_root / "extensions" / "cpp" / ext_name / "vendor" |
| 47 | + console.print(f"🎯 Injection Target: [blue]{dest_dir}[/blue]") |
| 48 | + |
| 49 | + if dry_run: |
| 50 | + console.print("⚠️ [yellow]DRY RUN[/yellow]: No files will be moved.") |
| 51 | + return |
| 52 | + |
| 53 | + if dest_dir.exists(): |
| 54 | + console.print("🧹 Cleaning previous injection...") |
| 55 | + shutil.rmtree(dest_dir) |
| 56 | + |
| 57 | + dest_dir.mkdir(parents=True, exist_ok=True) |
| 58 | + |
| 59 | + try: |
| 60 | + # Copy include |
| 61 | + shutil.copytree(sdk_path / "include", dest_dir / "include") |
| 62 | + # Copy lib |
| 63 | + shutil.copytree(sdk_path / "lib", dest_dir / "lib") |
| 64 | + # Copy doc |
| 65 | + if (sdk_path / "doc").exists(): |
| 66 | + shutil.copytree(sdk_path / "doc", dest_dir / "doc") |
| 67 | + |
| 68 | + console.print(f"🚀 [bold green]Success![/bold green] Injected {ext_name} SDK.") |
| 69 | + console.print("🔒 Security Note: 'vendor' directory is git-ignored.") |
| 70 | + |
| 71 | + except Exception as e: |
| 72 | + console.print(f"❌ [red]Injection Failed:[/red] {str(e)}") |
| 73 | + raise typer.Exit(code=1) |
0 commit comments