diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-01-09 18:01:15 +0800 |
commit | 47ebda69daa34ea7992b6bbadf46de98dd17a390 (patch) | |
tree | 8d169d75c9bd9a48f47383f245e371e57ea2eb8f /tools/cru-py/cru/service/__main__.py | |
parent | 43892b892cfdc4e15f7ab191c42ccb32279fd7f6 (diff) | |
download | crupest-47ebda69daa34ea7992b6bbadf46de98dd17a390.tar.gz crupest-47ebda69daa34ea7992b6bbadf46de98dd17a390.tar.bz2 crupest-47ebda69daa34ea7992b6bbadf46de98dd17a390.zip |
HALF WORK: 2024.1.9
Diffstat (limited to 'tools/cru-py/cru/service/__main__.py')
-rw-r--r-- | tools/cru-py/cru/service/__main__.py | 49 |
1 files changed, 7 insertions, 42 deletions
diff --git a/tools/cru-py/cru/service/__main__.py b/tools/cru-py/cru/service/__main__.py index 923c25b..c218bc6 100644 --- a/tools/cru-py/cru/service/__main__.py +++ b/tools/cru-py/cru/service/__main__.py @@ -1,45 +1,6 @@ -from pathlib import Path +from cru import CruUserFriendlyException -from cru import CruException - -from ._base import AppBase, DATA_DIR_NAME, CommandDispatcher -from ._config import ConfigManager -from ._data import DataManager -from ._template import TemplateManager - - -class App(AppBase): - def __init__(self, root: str): - super().__init__("crupest-service", root) - self.add_feature(DataManager()) - self.add_feature(ConfigManager()) - self.add_feature(TemplateManager()) - self.add_feature(CommandDispatcher()) - - def setup(self): - for feature in self.features: - feature.setup() - - def run_command(self): - command_dispatcher = self.get_feature(CommandDispatcher) - command_dispatcher.run_command() - - -def _find_root() -> Path: - cwd = Path.cwd() - data_dir = cwd / DATA_DIR_NAME - if data_dir.is_dir(): - return data_dir - raise CruException( - "No valid data directory found. Please run 'init' to create one." - ) - - -def create_app() -> App: - root = _find_root() - app = App(str(root)) - app.setup() - return app +from ._app import create_app def main(): @@ -48,4 +9,8 @@ def main(): if __name__ == "__main__": - main() + try: + main() + except CruUserFriendlyException as e: + print(f"Error: {e.user_message}") + exit(1) |