Files

53 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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