aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/cru/service
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-11-11 01:12:29 +0800
committerYuqian Yang <crupest@crupest.life>2024-12-22 17:45:13 +0800
commitb834953fa61d816b9a955640ad12d244316ce904 (patch)
tree4197980a04943b42941d3fce7cb16d1f7ea400bd /tools/cru-py/cru/service
parent7e85627eb0d0126baf1e698ffdeae0f3c5fc693d (diff)
downloadcrupest-b834953fa61d816b9a955640ad12d244316ce904.tar.gz
crupest-b834953fa61d816b9a955640ad12d244316ce904.tar.bz2
crupest-b834953fa61d816b9a955640ad12d244316ce904.zip
HALF WORK: 2024.12.22
code.
Diffstat (limited to 'tools/cru-py/cru/service')
-rw-r--r--tools/cru-py/cru/service/__main__.py11
-rw-r--r--tools/cru-py/cru/service/_base.py23
-rw-r--r--tools/cru-py/cru/service/_docker.py (renamed from tools/cru-py/cru/service/docker.py)0
-rw-r--r--tools/cru-py/cru/service/_manager.py2
-rw-r--r--tools/cru-py/cru/service/_template.py20
5 files changed, 56 insertions, 0 deletions
diff --git a/tools/cru-py/cru/service/__main__.py b/tools/cru-py/cru/service/__main__.py
new file mode 100644
index 0000000..a7add4d
--- /dev/null
+++ b/tools/cru-py/cru/service/__main__.py
@@ -0,0 +1,11 @@
+import argparse
+
+
+arg_parser = argparse.ArgumentParser(description="Service management")
+command_subparser = arg_parser.add_subparsers(dest="command")
+
+template_parser = command_subparser.add_parser("template", help="Template management")
+template_subparser = template_parser.add_subparsers(dest="template_command")
+
+template_subparser.add_parser('list', description="List templates")
+template_subparser.add_parser('generate')
diff --git a/tools/cru-py/cru/service/_base.py b/tools/cru-py/cru/service/_base.py
new file mode 100644
index 0000000..707fb66
--- /dev/null
+++ b/tools/cru-py/cru/service/_base.py
@@ -0,0 +1,23 @@
+from argparse import ArgumentParser, Namespace
+from typing import Protocol
+from cru.app import ApplicationPath, CruApplication
+
+
+class AppFunction(Protocol):
+ @property
+ def name(self) -> str: ...
+
+ def add_arg_parser(self, arg_parser: ArgumentParser) -> None: ...
+
+ def run_command(self, args: Namespace) -> None: ...
+
+
+class AppBase(CruApplication):
+ def __init__(self, name: str, app_dir: str):
+ super().__init__(name)
+ self._app_dir = app_dir
+ self._template_dir = ApplicationPath(app_dir, "templates", True)
+
+ @property
+ def app_dir(self) -> str:
+ return self._app_dir
diff --git a/tools/cru-py/cru/service/docker.py b/tools/cru-py/cru/service/_docker.py
index 5958f4f..5958f4f 100644
--- a/tools/cru-py/cru/service/docker.py
+++ b/tools/cru-py/cru/service/_docker.py
diff --git a/tools/cru-py/cru/service/_manager.py b/tools/cru-py/cru/service/_manager.py
index 45a9e47..c1af428 100644
--- a/tools/cru-py/cru/service/_manager.py
+++ b/tools/cru-py/cru/service/_manager.py
@@ -1,2 +1,4 @@
class CruServiceManager:
"TODO: Continue here tomorrow!"
+ def __init__(self):
+ \ No newline at end of file
diff --git a/tools/cru-py/cru/service/_template.py b/tools/cru-py/cru/service/_template.py
new file mode 100644
index 0000000..0ca4b63
--- /dev/null
+++ b/tools/cru-py/cru/service/_template.py
@@ -0,0 +1,20 @@
+from argparse import ArgumentParser, Namespace
+
+from ._base import AppBase, AppFunction
+
+
+class TemplateManager(AppFunction):
+ def __init__(self, app: AppBase):
+ self._app = app
+ pass
+
+ @property
+ def name(self):
+ return "template-manager"
+
+ def add_arg_parser(self, arg_parser: ArgumentParser) -> None:
+ subparsers = arg_parser.add_subparsers(dest="template_command")
+ list_parser = subparsers.add_parser("list", help="List templates")
+ generate_parser = subparsers.add_parser("generate", help="Generate template")
+
+ def run_command(self, args: Namespace) -> None: ...