fix: better init command
This commit is contained in:
parent
5ef1a586f5
commit
f03051df7e
31
osdk/cmds.py
31
osdk/cmds.py
|
@ -1,9 +1,9 @@
|
|||
import os
|
||||
import json
|
||||
import logging
|
||||
import tempfile
|
||||
import requests
|
||||
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from typing import Callable, cast
|
||||
|
||||
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):
|
||||
logger.info("Fetching registry...")
|
||||
r = requests.get('https://raw.githubusercontent.com/cute-engineering/osdk-template/main/registry.json')
|
||||
template = args.consumeArg()
|
||||
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:
|
||||
logger.error('Failed to fetch registry')
|
||||
exit(1)
|
||||
|
||||
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 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(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)]
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
VERSION = "0.4.1"
|
||||
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -12,3 +11,4 @@ EXTERN_DIR = os.path.join(OSDK_DIR, "extern")
|
|||
SRC_DIR = "src"
|
||||
META_DIR = f"meta"
|
||||
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)
|
||||
|
||||
|
||||
def mv(src: str, dst: str):
|
||||
logger.info(f"Moving {src} to {dst}")
|
||||
|
||||
shutil.move(src, dst)
|
||||
|
||||
|
||||
def cpTree(src: str, dst: str):
|
||||
logger.info(f"Copying {src} to {dst}")
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
requests ~= 2.28.0
|
||||
graphviz ~= 0.20.1
|
||||
pyfzf ~= 0.3.1
|
||||
graphviz ~= 0.20.1
|
Loading…
Reference in a new issue