This commit is contained in:
2025-03-01 00:25:01 +03:00
parent 3f7c577c29
commit fd4f2e1570
9 changed files with 103 additions and 41 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
from ..input_comand.exceptions import IncorrectInputFlagException, RepeatedInputFlagsException
from ..input_comand.exceptions import UnprocessedInputFlagException, RepeatedInputFlagsException
from ..entity import Command
from ..params.flag.flags_group.entity import FlagsGroup
from ..params.flag.input_flag.entity import InputFlag
@@ -29,12 +29,12 @@ class InputCommand(Command, Generic[T]):
if _.startswith('-'):
flag_prefix_last_symbol_index = _.rfind('-')
if current_flag_name or len(_) < 2 or len(_[:flag_prefix_last_symbol_index]) > 3:
raise IncorrectInputFlagException()
raise UnprocessedInputFlagException()
else:
current_flag_name = _
else:
if not current_flag_name:
raise IncorrectInputFlagException()
raise UnprocessedInputFlagException()
else:
current_flag_value = _
if current_flag_name and current_flag_value:
@@ -55,7 +55,7 @@ class InputCommand(Command, Generic[T]):
current_flag_name = None
current_flag_value = None
if any([current_flag_name, current_flag_value]):
raise IncorrectInputFlagException()
raise UnprocessedInputFlagException()
if len(flags.get_flags()) == 0:
return InputCommand(command=command)
else:
+8 -10
View File
@@ -1,16 +1,9 @@
from ..params.flag.input_flag.entity import InputFlag
class InvalidInputFlagException(Exception):
def __init__(self, flag: InputFlag):
self.flag = flag
class UnprocessedInputFlagException(Exception):
def __str__(self):
return ("Invalid Input Flags\n"
f"Unknown or invalid input flag: '{self.flag.get_string_entity()} {self.flag.get_value()}'")
class IncorrectInputFlagException(Exception):
def __str__(self):
return "Incorrect Input Flags"
return "Unprocessed Input Flags"
class RepeatedInputFlagsException(Exception):
@@ -26,12 +19,17 @@ class InvalidInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
return "Invalid Input Flags Handler has already been created"
class RepeatedInputFlagsHandlerHasBeenAlreadyCreatedException(Exception):
def __str__(self):
return "Repeated Input Flags Handler has already been created"
class UnknownCommandHandlerHasBeenAlreadyCreatedException(Exception):
def __str__(self):
return "Unknown Command Handler has already been created"
class IncorrectNumberArgsHandlerException(Exception):
class IncorrectNumberOfHandlerArgsException(Exception):
def __str__(self):
return "Incorrect Input Flags Handler has incorrect number of arguments"
@@ -20,3 +20,6 @@ class FlagsGroup:
def __next__(self):
return next(iter(self))
def __getitem__(self, item):
return self._flags[item]