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