| Total Complexity | 8 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import abc |
||
|
|
|||
| 2 | import argparse |
||
| 3 | |||
| 4 | from typing import Callable |
||
| 5 | from typing import List |
||
| 6 | from typing import Text |
||
| 7 | from typing import Type |
||
| 8 | |||
| 9 | from .lang import classproperty_readonly |
||
| 10 | from .utils import print_out |
||
| 11 | |||
| 12 | |||
| 13 | class BaseCommandExecutor(abc.ABC): |
||
| 14 | |||
| 15 | @abc.abstractmethod |
||
| 16 | def __init__(self, args: argparse.Namespace) -> None: |
||
| 17 | ... |
||
| 18 | |||
| 19 | @abc.abstractmethod |
||
| 20 | def __call__(self) -> None: |
||
| 21 | ... |
||
| 22 | |||
| 23 | @staticmethod |
||
| 24 | def _print_input_args(**kwargs) -> None: |
||
| 25 | print_out(f"input args: {kwargs}") |
||
| 26 | |||
| 27 | |||
| 28 | class BaseCommand(abc.ABC): |
||
| 29 | |||
| 30 | @classproperty_readonly |
||
| 31 | def name(self) -> Text: |
||
| 32 | raise NotImplementedError |
||
| 33 | |||
| 34 | @classproperty_readonly |
||
| 35 | def aliases(self) -> List[Text]: |
||
| 36 | return [] |
||
| 37 | |||
| 38 | @classproperty_readonly |
||
| 39 | def executor_class(self) -> Type[BaseCommandExecutor]: |
||
| 40 | raise NotImplementedError |
||
| 41 | |||
| 42 | @classmethod |
||
| 43 | def make_executor(cls, args=argparse.Namespace) -> BaseCommandExecutor: |
||
| 44 | return cls.executor_class(args) |
||
| 45 | |||
| 46 | @classmethod |
||
| 47 | @abc.abstractmethod |
||
| 48 | def make_parser(cls, factory=argparse.ArgumentParser) -> argparse.ArgumentParser: |
||
| 49 | ... |
||
| 50 |