fix: check if templates is valid + exists
This commit is contained in:
parent
5a926057a7
commit
b0f18a83d2
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
import requests
|
import requests
|
||||||
|
@ -246,18 +245,23 @@ def initCmd(args: Args):
|
||||||
repo = const.DEFAULT_REPO_TEMPLATES if not "repo" in args.opts else args.opts["repo"]
|
repo = const.DEFAULT_REPO_TEMPLATES if not "repo" in args.opts else args.opts["repo"]
|
||||||
list = "list" in args.opts
|
list = "list" in args.opts
|
||||||
|
|
||||||
|
logger.info("Fetching registry...")
|
||||||
|
r = requests.get(
|
||||||
|
f'https://raw.githubusercontent.com/{repo}/main/registry.json')
|
||||||
|
|
||||||
|
if r.status_code != 200:
|
||||||
|
logger.error('Failed to fetch registry')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
registry = r.json()
|
||||||
|
|
||||||
if list:
|
if list:
|
||||||
logger.info("Fetching registry...")
|
|
||||||
r = requests.get(
|
|
||||||
f'https://raw.githubusercontent.com/{repo}/main/registry.json')
|
|
||||||
|
|
||||||
if r.status_code != 200:
|
|
||||||
logger.error('Failed to fetch registry')
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
print('\n'.join(
|
print('\n'.join(
|
||||||
f"* {entry['id']} - {entry['description']}" for entry in json.loads(r.text)))
|
f"* {entry['id']} - {entry['description']}" for entry in registry))
|
||||||
else:
|
else:
|
||||||
|
if not any(filter(lambda t: t['id'] == template, registry)):
|
||||||
|
raise RuntimeError(f"Unknown template {template}")
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
shell.exec(*["git", "clone", "-n", "--depth=1",
|
shell.exec(*["git", "clone", "-n", "--depth=1",
|
||||||
"--filter=tree:0", f"https://github.com/{repo}", tmp, "-q"])
|
"--filter=tree:0", f"https://github.com/{repo}", tmp, "-q"])
|
||||||
|
|
Loading…
Reference in a new issue