2022-06-17 13:21:35 +01:00
|
|
|
import argparse
|
|
|
|
from abc import abstractmethod
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2024-12-06 18:15:47 +00:00
|
|
|
_SubparserType = argparse._SubParsersAction[
|
|
|
|
argparse.ArgumentParser
|
|
|
|
] # pylint: disable=protected-access
|
2022-06-17 13:21:35 +01:00
|
|
|
else:
|
|
|
|
_SubparserType = Any
|
|
|
|
|
|
|
|
|
|
|
|
class BaseCliHandler:
|
|
|
|
def __init__(self, args: argparse.Namespace) -> None:
|
|
|
|
self.args = args
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@abstractmethod
|
|
|
|
def add_subparser_to(cls, subparsers: _SubparserType) -> None:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def run(self) -> None:
|
|
|
|
raise NotImplementedError
|