aides-spec/aides_spec/commands/create.py
2025-01-05 11:37:11 +03:00

39 lines
1.2 KiB
Python

import sys
from typing import Annotated, Optional
import typer
from aides_spec.utils.empty_template import create_from_empty_template
from aides_spec.utils.from_pkgbuild import (
create_from_pkgbuild,
download_pkgbuild,
)
app = typer.Typer()
@app.command()
def create(
from_aur: Annotated[Optional[str], typer.Option()] = None,
from_pkgbuild: Annotated[Optional[str], typer.Option()] = None,
empty_template: Annotated[Optional[bool], typer.Option()] = None,
):
output_file = "alr.sh"
if empty_template:
create_from_empty_template(output_file)
elif from_aur:
print(f"Загружаем PKGBUILD для пакета '{from_aur}' из AUR...")
content = download_pkgbuild(from_aur)
create_from_pkgbuild(content, output_file)
elif from_pkgbuild:
print(f"Читаем PKGBUILD из локального файла '{from_pkgbuild}'...")
try:
with open(from_pkgbuild, "rb") as f:
content = f.read()
create_from_pkgbuild(content, output_file)
except IOError as e:
print(f"Ошибка чтения файла '{from_pkgbuild}': {e}")
sys.exit(1)
else:
sys.exit(1)