Coverage for aipyapp/cli/command/base.py: 0%

1 from enum import Enum

2 from typing import List

3

4 from loguru import logger

5

6 class CommandMode(Enum):

7 MAIN = "main"

8 TASK = "task"

9

10 class Completable:

11 def __init__(self, name: str, desc=None, **kwargs):

12 super().__init__()

13 self.name = name

14 self.desc = desc

15 self._options = kwargs

16

17 def __getitem__(self, key):

18 return self._options[key]

19

20 def __setitem__(self, key, value):

21 self._options[key] = value

22

23 def __contains__(self, key):

24 return key in self._options

25

26 def get(self, key, default=None):

27 return self._options.get(key, default)

28

29 class BaseCommand(Completable):

30 """Base class for all commands"""

31 name: str = ''

32 description: str = ''

33 modes: List[CommandMode] = [CommandMode.MAIN]

34

35 def __init__(self, manager):

36 super().__init__(self.name, self.description)

37 self.manager = manager

38 self.log = logger.bind(src=f'cmd.{self.name}')

39

40 def execute(self, args, context=None):

41 pass