add basics
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import typer
|
||||
from pathlib import Path
|
||||
from jeAddons.registry import load_registry
|
||||
from jeAddons.copier import fetch_file
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
@app.command()
|
||||
def add(name: str):
|
||||
registry = load_registry()
|
||||
|
||||
if name not in registry:
|
||||
typer.echo(f"❌ Unknown entry: {name}")
|
||||
raise typer.Exit(1)
|
||||
|
||||
entry = registry[name]
|
||||
fetch_file(entry["repo"], entry["file"], Path.cwd())
|
||||
|
||||
typer.echo(f"✅ Added {entry['file']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
@@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
import tempfile
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def fetch_file(repo_url: str, file_path: str, dest: Path):
|
||||
tmp = tempfile.mkdtemp()
|
||||
|
||||
subprocess.check_call(["git", "clone", "--depth", "1", repo_url, tmp])
|
||||
|
||||
src = Path(tmp) / file_path
|
||||
if not src.exists():
|
||||
raise FileNotFoundError(file_path)
|
||||
|
||||
shutil.copy2(src, dest / src.name)
|
||||
@@ -0,0 +1,9 @@
|
||||
import json
|
||||
import urllib.request
|
||||
|
||||
REGISTRY_URL = "https://raw.githubusercontent.com/acme/registry/main/registry.json"
|
||||
|
||||
|
||||
def load_registry():
|
||||
with urllib.request.urlopen(REGISTRY_URL) as r:
|
||||
return json.load(r)
|
||||
Reference in New Issue
Block a user