feat: add task tag
This commit is contained in:
+19
-12
@@ -1,11 +1,11 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Iterable
|
||||
from typing import Iterable, NamedTuple
|
||||
|
||||
from .common.command import CommandExecutor
|
||||
|
||||
__all__ = (
|
||||
"EntryTaskNotImplementedError",
|
||||
"TaskKey",
|
||||
"Entry",
|
||||
"EntryDetector",
|
||||
"EntryResolver",
|
||||
@@ -14,8 +14,12 @@ __all__ = (
|
||||
logger = logging.getLogger("entry")
|
||||
|
||||
|
||||
class EntryTaskNotImplementedError(NotImplementedError):
|
||||
pass
|
||||
class TaskKey(NamedTuple):
|
||||
name: str
|
||||
tag: str
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.name}:{self.tag}"
|
||||
|
||||
|
||||
class Entry:
|
||||
@@ -23,7 +27,7 @@ class Entry:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
tasks: dict[str, list[str]],
|
||||
tasks: dict[TaskKey, list[str]],
|
||||
basepath: Path,
|
||||
):
|
||||
self._tasks = tasks
|
||||
@@ -36,15 +40,18 @@ class Entry:
|
||||
for command in commands:
|
||||
self._logger.debug(" %s", command)
|
||||
|
||||
def run_task(self, task_name: str):
|
||||
def run_task(self, task_name: str, tag: str | None = None) -> bool:
|
||||
if task_name == "show":
|
||||
self.show()
|
||||
return
|
||||
if task_name not in self._tasks:
|
||||
raise EntryTaskNotImplementedError(task_name)
|
||||
self._logger.info("%s %s", task_name, self)
|
||||
for command in self._tasks[task_name]:
|
||||
CommandExecutor(command).run(self._basepath)
|
||||
return True
|
||||
runned = False
|
||||
for task_key, commands in self._tasks.items():
|
||||
if task_key.name == task_name and (tag is None or tag == task_key.tag):
|
||||
self._logger.info("%s %s", task_key, self)
|
||||
runned = True
|
||||
for command in commands:
|
||||
CommandExecutor(command).run(self._basepath)
|
||||
return runned
|
||||
|
||||
def __repr__(self):
|
||||
return f"{str(self._basepath)}"
|
||||
|
||||
Reference in New Issue
Block a user