Coverage for src/probable_fiesta/command/builder/command.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-01-30 18:57 -0500

1"""Command class.""" 

2class Command: 

3 

4 def __init__(self, name, function, *args): 

5 self.name = name 

6 self.function = function 

7 self.args = args 

8 

9 def __str__(self): 

10 return f"Command: {self.__dict__}" 

11 

12 def invoke(self): 

13 if self.function is not None and self.args is not None: 

14 if self.args[0] is not None: 

15 return self.function(*self.args) 

16 return self.function() 

17 #elif self.function is not None and self.args is None: 

18 #return self.function() 

19 return None 

20 

21 class Factory(): 

22 

23 @staticmethod 

24 def new_command(name, function, *args): 

25 return Command(name, function, *args) 

26 

27 factory = Factory()