69 lines
1.4 KiB
Python
69 lines
1.4 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
from cpl.cli.cli import cli
|
|
from cpl.cli.command.init import init
|
|
from cpl.cli.command.install import install
|
|
from cpl.cli.command.uninstall import uninstall
|
|
from cpl.cli.command.update import update
|
|
from cpl.cli.model.workspace import Workspace
|
|
from cpl.cli.utils.custom_command import script_command
|
|
from cpl.core.configuration import Configuration
|
|
|
|
|
|
def _load_workspace(path: str) -> Workspace | None:
|
|
path = Path(path)
|
|
if not path.exists() or path.is_dir():
|
|
return None
|
|
|
|
return Workspace.from_file(path)
|
|
|
|
|
|
def _load_scripts():
|
|
for p in [
|
|
"./cpl.workspace.json",
|
|
"../cpl.workspace.json",
|
|
"../../cpl.workspace.json",
|
|
]:
|
|
ws = _load_workspace(p)
|
|
if ws is None:
|
|
continue
|
|
|
|
Configuration.set("workspace_path", os.path.abspath(p))
|
|
return ws.scripts
|
|
|
|
return {}
|
|
|
|
|
|
def prepare():
|
|
scripts = _load_scripts()
|
|
for name, command in scripts.items():
|
|
script_command(cli, name, command)
|
|
|
|
|
|
def configure():
|
|
cli.add_command(init)
|
|
cli.add_command(install)
|
|
cli.add_command(uninstall)
|
|
cli.add_command(update)
|
|
|
|
|
|
def main():
|
|
prepare()
|
|
configure()
|
|
cli()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# ((
|
|
# ( `)
|
|
# ; / ,
|
|
# / \/
|
|
# / |
|
|
# / ~/
|
|
# / ) ) ~ edraft
|
|
# ___// | /
|
|
# `--' \_~-,
|