|
| 1 | +import typer |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +from pathlib import Path |
| 5 | +from rich.console import Console |
| 6 | + |
| 7 | +app = typer.Typer() |
| 8 | +console = Console() |
| 9 | + |
| 10 | +def get_project_root() -> Path: |
| 11 | + """Find the project root.""" |
| 12 | + # Assuming this is run from within the repo, finding where 'quanuxctl' or 'server' is |
| 13 | + # Using the current file path |
| 14 | + current_file = Path(__file__).resolve() |
| 15 | + # Path: server/cli/src/quanuxctl/commands/geminicli.py |
| 16 | + # Root: ../../../../../../ |
| 17 | + return current_file.parents[5] |
| 18 | + |
| 19 | +@app.command() |
| 20 | +def install(): |
| 21 | + """ |
| 22 | + Install the QuanuX Gemini CLI Extension locally. |
| 23 | + """ |
| 24 | + root = get_project_root() |
| 25 | + extension_path = root / "extensions" / "python" / "gemini-cli-extension" |
| 26 | + |
| 27 | + if not extension_path.exists(): |
| 28 | + console.print(f"[bold red]Error:[/bold red] Extension path not found: {extension_path}") |
| 29 | + raise typer.Exit(1) |
| 30 | + |
| 31 | + console.print(f"[bold blue]Installing extension from:[/bold blue] {extension_path}") |
| 32 | + |
| 33 | + try: |
| 34 | + # Check if gemini is installed |
| 35 | + subprocess.run(["gemini", "--version"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 36 | + |
| 37 | + # Install |
| 38 | + subprocess.run(["gemini", "extension", "install", str(extension_path)], check=True) |
| 39 | + console.print("[bold green]Successfully installed QuanuX Gemini Extension![/bold green]") |
| 40 | + |
| 41 | + except FileNotFoundError: |
| 42 | + console.print("[bold red]Error:[/bold red] 'gemini' command not found. Please install Gemini CLI first.") |
| 43 | + raise typer.Exit(1) |
| 44 | + except subprocess.CalledProcessError as e: |
| 45 | + console.print(f"[bold red]Installation failed:[/bold red] {e}") |
| 46 | + raise typer.Exit(1) |
| 47 | + |
| 48 | +@app.command() |
| 49 | +def remove(): |
| 50 | + """ |
| 51 | + Remove the QuanuX Gemini CLI Extension. |
| 52 | + """ |
| 53 | + try: |
| 54 | + # Check if gemini is installed |
| 55 | + subprocess.run(["gemini", "--version"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 56 | + |
| 57 | + # Uninstall using the ID defined in gemini-extension.json |
| 58 | + subprocess.run(["gemini", "extension", "uninstall", "quanux-mcp"], check=True) |
| 59 | + console.print("[bold green]Successfully removed QuanuX Gemini Extension.[/bold green]") |
| 60 | + |
| 61 | + except FileNotFoundError: |
| 62 | + console.print("[bold red]Error:[/bold red] 'gemini' command not found.") |
| 63 | + raise typer.Exit(1) |
| 64 | + except subprocess.CalledProcessError as e: |
| 65 | + console.print(f"[bold red]Removal failed:[/bold red] {e}") |
| 66 | + raise typer.Exit(1) |
0 commit comments