diff options
| author | 2024-01-24 19:51:32 +0800 | |
|---|---|---|
| committer | 2024-01-24 19:51:32 +0800 | |
| commit | 4fa42f68616ab53a7f2aa04382cddf43db77d4a5 (patch) | |
| tree | 7f67b126efd08a0903a77388bf03a4723b70e98b /src | |
| parent | ac4313dfec1d7d18550d22986aa33aed65d41fd1 (diff) | |
| download | ipm-4fa42f68616ab53a7f2aa04382cddf43db77d4a5.tar.gz ipm-4fa42f68616ab53a7f2aa04382cddf43db77d4a5.zip | |
:sparkles: feat(ci): pre-asking when init infini project
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipm/api.py | 25 | ||||
| -rw-r--r-- | src/ipm/logging.py | 16 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/ipm/api.py b/src/ipm/api.py index 84ae92b..e0ee64f 100644 --- a/src/ipm/api.py +++ b/src/ipm/api.py @@ -2,7 +2,7 @@ from pathlib import Path from .typing import StrPath from .utils import freeze, urlparser, loader from .const import INDEX, INDEX_PATH, STORAGE, SRC_HOME -from .logging import update, info, success, warning, error, confirm, tada +from .logging import status, update, info, success, warning, error, confirm, ask from .exceptions import ( FileTypeMismatch, TomlLoadFailed, @@ -20,10 +20,17 @@ import shutil def check(source_path: StrPath, echo: bool = False) -> bool: info("项目环境检查...", echo) - ProjectLock( + + update("检查环境...") + lock = ProjectLock( Path(source_path).resolve() / "infini.lock", auto_load=False, - ).init() + ) + success("环境检查完毕.", echo) + + update("写入依赖锁文件...", echo) + lock.init() + success("项目依赖锁写入完成.", echo) return True @@ -37,15 +44,21 @@ def init(source_path: StrPath, force: bool = False, echo: bool = False) -> bool: echo, ) success("环境检查完毕.", echo) + status.stop() + + name = ask("项目名称:", default=source_path.name, echo=echo) + description = ask("项目简介:", default=f"{source_path.name.upper()} 规则包", echo=echo) + license = ask("开源协议:", default="MIT", echo=echo) + status.start() toml_file = toml_path.open("w", encoding="utf-8") toml.dump( { "infini": { - "name": source_path.name, + "name": name, "version": "0.1.0", - "description": f"{source_path.name.upper()} 规则包", - "license": "MIT", + "description": description, + "license": license, }, "requirements": {}, "dependencies": {}, diff --git a/src/ipm/logging.py b/src/ipm/logging.py index 369c8f2..17fb965 100644 --- a/src/ipm/logging.py +++ b/src/ipm/logging.py @@ -1,5 +1,6 @@ from rich.console import Console -from rich.prompt import Confirm +from rich.prompt import Confirm, Prompt +from .typing import List, Any console = Console() status = console.status("") @@ -45,5 +46,14 @@ def tada(message: str = "工作完成!", echo: bool = True) -> None: return console.print("\n[red]:tada:[/red]", str(message), "\n") if echo else None -def confirm(messgae: str, default: bool = False) -> bool: - return Confirm.ask(str(messgae), default=default) +def confirm(message: str, default: bool = False) -> bool: + return Confirm.ask(str(message), default=default) + + +def ask( + message: str, + choices: List[str] | None = None, + default: Any = None, + echo: bool = False, +) -> Any: + return Prompt.ask(message, choices=choices, default=default) if echo else default |
