diff --git a/argenta/command/entity.py b/argenta/command/entity.py index 1a59f21..3cc8c0d 100644 --- a/argenta/command/entity.py +++ b/argenta/command/entity.py @@ -14,7 +14,7 @@ class Command: self._description = description self._flags = flags - self._input_flags: FlagsGroup | None = None + self._input_flags: InputFlag | FlagsGroup | None = None def get_string_entity(self): return self._command @@ -37,17 +37,23 @@ class Command: raise InvalidCommandInstanceException(self._command) if not isinstance(self._description, str): raise InvalidDescriptionInstanceException() - if not (isinstance(self._flags, Flag) or not isinstance(self._flags, FlagsGroup)) or not self._flags is None: + if not any([(isinstance(self._flags, Flag), isinstance(self._flags, FlagsGroup)), not self._flags]): raise InvalidFlagsInstanceException def validate_input_flag(self, flag: InputFlag): - registered_flags: FlagsGroup = self._flags + registered_flags: FlagsGroup | Flag | None = self._flags if registered_flags: - for registered_flag in registered_flags: - if registered_flag.get_string_entity() == flag.get_string_entity(): - is_valid = registered_flag.validate_input_flag_value(flag) + if isinstance(registered_flags, Flag): + if registered_flags.get_string_entity() == flag.get_string_entity(): + is_valid = registered_flags.validate_input_flag_value(flag.get_value()) if is_valid: return True + else: + for registered_flag in registered_flags: + if registered_flag.get_string_entity() == flag.get_string_entity(): + is_valid = registered_flag.validate_input_flag_value(flag.get_value()) + if is_valid: + return True return False diff --git a/argenta/command/input_comand/__pycache__/entity.cpython-313.pyc b/argenta/command/input_comand/__pycache__/entity.cpython-313.pyc index d46837d..ae03cc9 100644 Binary files a/argenta/command/input_comand/__pycache__/entity.cpython-313.pyc and b/argenta/command/input_comand/__pycache__/entity.cpython-313.pyc differ diff --git a/argenta/command/input_comand/entity.py b/argenta/command/input_comand/entity.py index 82e51f7..ba31a10 100644 --- a/argenta/command/input_comand/entity.py +++ b/argenta/command/input_comand/entity.py @@ -50,6 +50,8 @@ class InputCommand(Command, Generic[T]): current_flag_name = None current_flag_value = None + if any([current_flag_name, current_flag_value]): + raise IncorrectInputFlagException() if len(flags.get_flags()) == 0: return InputCommand(command=command) else: diff --git a/argenta/command/params/flag/entity.py b/argenta/command/params/flag/entity.py index 8953a0f..c772a4d 100644 --- a/argenta/command/params/flag/entity.py +++ b/argenta/command/params/flag/entity.py @@ -18,7 +18,6 @@ class Flag: string_entity: str = self.flag_prefix + self.flag_name.lower() else: string_entity: str = self.flag_prefix + self.flag_name - print(string_entity) return string_entity def get_value(self): diff --git a/tests/mock_app/handlers/routers.py b/tests/mock_app/handlers/routers.py index bfb5d98..1087383 100644 --- a/tests/mock_app/handlers/routers.py +++ b/tests/mock_app/handlers/routers.py @@ -1,6 +1,7 @@ from rich.console import Console from argenta.command.entity import Command +from argenta.command.params.flag.entity import Flag from argenta.command.params.flag.flags_group.entity import FlagsGroup from argenta.router import Router @@ -12,11 +13,15 @@ settings_router: Router = Router(title='Settings points:') console = Console() -@work_router.command(command=Command(command='0', description='Get Help')) +@work_router.command(command=Command(command='0', description='Get Help', flags=Flag(flag_name='host', + flag_prefix='--', + ignore_flag_value_register=True, + possible_flag_values=['tester', 'ffmpeg']))) def command_help(args: FlagsGroup): - print(args.get_flags()) - print('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') - help_command() + flags = args.get_flags() + for flag in flags: + print(f'name: "{flag.get_string_entity()}", value: "{flag.get_value()}"') + #help_command() '''@work_router.command(command='1', description='Start Solving')