- Replaces direct config usage with RepoCatalogState to manage categories and repositories, improving modularity and encapsulation. - Updates repository movement logic to use `RepoCatalogState` methods for better abstraction and error handling.
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
from typer import Typer, Argument
|
|
from rich.console import Console
|
|
import typer
|
|
|
|
from repocat.config import load_config
|
|
from repocat.models.catalog import RepoCatalogState
|
|
|
|
app = Typer()
|
|
console = Console()
|
|
|
|
|
|
def complete_source_repo(incomplete: str):
|
|
config = load_config()
|
|
catalog = RepoCatalogState.from_config(config)
|
|
results = []
|
|
|
|
for cat in catalog.categories:
|
|
if cat.config.is_archive:
|
|
continue
|
|
for repo in cat.repos:
|
|
full_name = f"{cat.config.name}/{repo.name}"
|
|
if full_name.startswith(incomplete):
|
|
results.append(full_name)
|
|
return sorted(results)
|
|
|
|
|
|
def complete_category(incomplete: str):
|
|
config = load_config()
|
|
return [c.name for c in config.categories if c.name.startswith(incomplete) and c.name != "archive"]
|
|
|
|
|
|
@app.command("move")
|
|
def move_command(
|
|
source: str = Argument(..., help="Quell-Repo im Format <category>/<reponame>", autocompletion=complete_source_repo),
|
|
target: str = Argument(..., help="Zielkategorie", autocompletion=complete_category),
|
|
):
|
|
"""
|
|
Verschiebt ein Repository in eine andere Kategorie.
|
|
"""
|
|
config = load_config()
|
|
catalog = RepoCatalogState.from_config(config)
|
|
|
|
try:
|
|
source_cat_name, repo_name = source.split("/", 1)
|
|
except ValueError:
|
|
console.print("[red]Ungültiges Format für Quelle. Bitte <kategorie>/<reponame> angeben.[/]")
|
|
raise typer.Exit(1)
|
|
|
|
source_cat = catalog.get_category(source_cat_name)
|
|
if not source_cat:
|
|
console.print(f"[red]Unbekannte Quellkategorie:[/] {source_cat_name}")
|
|
raise typer.Exit(1)
|
|
|
|
target_cat = catalog.get_category(target)
|
|
if not target_cat:
|
|
console.print(f"[red]Ungültige Zielkategorie:[/] {target}")
|
|
raise typer.Exit(1)
|
|
|
|
repo = source_cat.find_repo(repo_name)
|
|
if not repo:
|
|
console.print(f"[red]Repository '{repo_name}' nicht gefunden in Kategorie '{source_cat_name}'.[/]")
|
|
raise typer.Exit(1)
|
|
|
|
try:
|
|
repo.move_to(target_cat.path)
|
|
console.print(f"[green]✓ Erfolgreich verschoben:[/] {source_cat_name}/{repo_name} → {target}")
|
|
except FileExistsError as e:
|
|
console.print(f"[red]{e}[/]")
|
|
raise typer.Exit(1)
|
|
except Exception as e:
|
|
console.print(f"[red]Fehler beim Verschieben:[/] {e}")
|
|
raise typer.Exit(1) |