Initial gradle-mirror CLI project

This commit is contained in:
2026-04-08 12:33:06 +03:30
commit 1e6b55d20b
12 changed files with 589 additions and 0 deletions

52
gradle_mirror/cli.py Normal file
View File

@@ -0,0 +1,52 @@
"""Typer CLI entrypoint for gradle-mirror."""
from __future__ import annotations
import typer
from .gradle_locator import detect_gradle_user_home
from .mirror_manager import MirrorManager
from .utils import setup_logger
app = typer.Typer(
add_completion=False,
no_args_is_help=True,
help="Activate/deactivate Gradle mirror repositories via init.gradle.kts.",
)
def _build_manager() -> MirrorManager:
gradle_home = detect_gradle_user_home()
logger = setup_logger(gradle_home)
return MirrorManager(gradle_home=gradle_home, logger=logger)
@app.command()
def active() -> None:
"""Activate global mirror configuration."""
try:
manager = _build_manager()
result = manager.activate()
typer.secho(f"{result.message}", fg=typer.colors.GREEN)
typer.secho(f"📁 Updated {result.init_file}", fg=typer.colors.BRIGHT_BLUE)
except Exception as exc: # pragma: no cover - top-level safety
typer.secho(f"❌ Failed to activate mirror: {exc}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=1) from exc
@app.command()
def deactive() -> None:
"""Deactivate mirror configuration."""
try:
manager = _build_manager()
result = manager.deactivate()
color = typer.colors.YELLOW if not result.changed else typer.colors.GREEN
emoji = "" if not result.changed else ""
typer.secho(f"{emoji} {result.message}", fg=color)
if result.init_file.exists():
typer.secho(f"📁 Current file {result.init_file}", fg=typer.colors.BRIGHT_BLUE)
except Exception as exc: # pragma: no cover - top-level safety
typer.secho(f"❌ Failed to deactivate mirror: {exc}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=1) from exc