feat: rework default entries

This commit is contained in:
2023-03-15 10:26:33 +03:00
parent 9345b27aef
commit 23ca8c0cac
14 changed files with 101 additions and 116 deletions
+19 -16
View File
@@ -6,7 +6,9 @@ __all__ = (
import logging
from pathlib import Path
from typing import Optional
from typing import Dict, List, Optional
from .command import Command
logger = logging.getLogger("entry")
@@ -18,24 +20,25 @@ class EntryCommandNotImplementedError(NotImplementedError):
class Entry:
_logger = logger
def __init__(self, entry_type: str, basepath: Path):
def __init__(
self,
entry_type: str,
commands: Dict[str, List[List[str]]],
basepath: Path,
):
self._type = entry_type
self._commands = commands
self._basepath = basepath
def setup(self):
raise EntryCommandNotImplementedError("setup")
def lint(self):
raise EntryCommandNotImplementedError("lint")
def format(self):
raise EntryCommandNotImplementedError("format")
def test(self):
raise EntryCommandNotImplementedError("test")
def show(self):
self._logger.info(f"{self}")
def run_command(self, command_name: str):
if command_name == "show":
self._logger.info(f"{self}")
return
self._logger.info(f"{command_name} {self}")
if command_name not in self._commands:
raise EntryCommandNotImplementedError(command_name)
for command in self._commands[command_name]:
Command(*command).run(self._basepath)
def __repr__(self):
return f"{self._type} {str(self._basepath)}"