fix: better init command
This commit is contained in:
parent
6e3c8bfd80
commit
00537aa34e
31
osdk/cmds.py
31
osdk/cmds.py
|
@ -1,9 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import tempfile
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
|
||||||
from typing import Callable, cast
|
from typing import Callable, cast
|
||||||
|
|
||||||
from osdk import context, shell, const, vt100, builder, graph
|
from osdk import context, shell, const, vt100, builder, graph
|
||||||
|
@ -211,20 +211,25 @@ cmds += [Cmd("i", "install", "Install all the external packages", installCmd)]
|
||||||
|
|
||||||
|
|
||||||
def initCmd(args: Args):
|
def initCmd(args: Args):
|
||||||
logger.info("Fetching registry...")
|
template = args.consumeArg()
|
||||||
r = requests.get('https://raw.githubusercontent.com/cute-engineering/osdk-template/main/registry.json')
|
repo = const.DEFAULT_REPO_TEMPLATES if not "repo" in args.opts else args.opts["repo"]
|
||||||
|
list = "list" in args.opts
|
||||||
|
|
||||||
if r.status_code != 200:
|
if list:
|
||||||
logger.error('Failed to fetch registry')
|
logger.info("Fetching registry...")
|
||||||
exit(1)
|
r = requests.get(f'https://raw.githubusercontent.com/{repo}/main/registry.json')
|
||||||
|
|
||||||
registry = json.loads(r.text)
|
|
||||||
_fzf = FzfPrompt()
|
|
||||||
|
|
||||||
result = _fzf.prompt([f"{r['id']} - {r['description']}" for r in registry], "--cycle --header='Select a template:'")
|
|
||||||
result = result[0].split(' - ')[0].strip()
|
|
||||||
os.system(f'svn --quiet checkout https://github.com/cute-engineering/osdk-template/trunk/{result}')
|
|
||||||
|
|
||||||
|
if r.status_code != 200:
|
||||||
|
logger.error('Failed to fetch registry')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
print('\n'.join(f"* {entry['id']} - {entry['description']}" for entry in json.loads(r.text)))
|
||||||
|
else:
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
shell.exec(*["git", "clone", "-n", "--depth=1", "--filter=tree:0", f"https://github.com/{repo}", os.path.join(tmp, "osdk-repo"), "-q"])
|
||||||
|
shell.exec(*["git", "-C", os.path.join(tmp, "osdk-repo"), "sparse-checkout", "set", "--no-cone", template, "-q"])
|
||||||
|
shell.exec(*["git", "-C", os.path.join(tmp, "osdk-repo"), "checkout", "-q"])
|
||||||
|
shell.mv(os.path.join(tmp, "osdk-repo", template), os.path.join(".", template))
|
||||||
|
|
||||||
cmds += [Cmd("I", "init", "Start a new project", initCmd)]
|
cmds += [Cmd("I", "init", "Start a new project", initCmd)]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
|
||||||
|
|
||||||
VERSION = "0.4.1"
|
VERSION = "0.4.1"
|
||||||
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
|
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -12,3 +11,4 @@ EXTERN_DIR = os.path.join(OSDK_DIR, "extern")
|
||||||
SRC_DIR = "src"
|
SRC_DIR = "src"
|
||||||
META_DIR = f"meta"
|
META_DIR = f"meta"
|
||||||
TARGETS_DIR = os.path.join(META_DIR, "targets")
|
TARGETS_DIR = os.path.join(META_DIR, "targets")
|
||||||
|
DEFAULT_REPO_TEMPLATES = "cute-engineering/osdk-template"
|
|
@ -179,6 +179,12 @@ def cp(src: str, dst: str):
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
|
|
||||||
|
|
||||||
|
def mv(src: str, dst: str):
|
||||||
|
logger.info(f"Moving {src} to {dst}")
|
||||||
|
|
||||||
|
shutil.move(src, dst)
|
||||||
|
|
||||||
|
|
||||||
def cpTree(src: str, dst: str):
|
def cpTree(src: str, dst: str):
|
||||||
logger.info(f"Copying {src} to {dst}")
|
logger.info(f"Copying {src} to {dst}")
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
requests ~= 2.28.0
|
requests ~= 2.28.0
|
||||||
graphviz ~= 0.20.1
|
graphviz ~= 0.20.1
|
||||||
pyfzf ~= 0.3.1
|
|
Loading…
Reference in a new issue