From d94b25d9d8c7f5306b52b80d6e55588bd3a1e62d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 19:43:30 +0200 Subject: [PATCH] Improved configuration console argument handling --- src/cpl/configuration/configuration.py | 44 ++++++++++---------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/cpl/configuration/configuration.py b/src/cpl/configuration/configuration.py index 72959a94..4c7edc7b 100644 --- a/src/cpl/configuration/configuration.py +++ b/src/cpl/configuration/configuration.py @@ -104,32 +104,6 @@ class Configuration(ConfigurationABC): else: self._config[name] = value - def _validate_argument_child(self, argument: str, argument_type: ConsoleArgument, - next_arguments: Optional[list[str]]) -> bool: - """ - Validates the child arguments of argument - :param argument: - :param argument_type: - :param next_arguments: - :return: - """ - if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0: - found = False - for child_argument_type in argument_type.console_arguments: - found = self._validate_argument_by_argument_type(argument, child_argument_type, next_arguments) - if found and child_argument_type.name not in self._additional_arguments: - self._additional_arguments.append(child_argument_type.name) - - if found: - break - - if not found: - raise Exception(f'Invalid argument: {argument}') - - return found - - return True - def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument, next_arguments: list[str] = None) -> bool: """ @@ -246,7 +220,23 @@ class Configuration(ConfigurationABC): next_args = [] if len(next_arguments) > 1: next_args = next_arguments[1:] - result = self._validate_argument_child(next_arguments[0], argument_type, next_args) + + if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0: + found_child = False + for child_argument_type in argument_type.console_arguments: + found_child = self._validate_argument_by_argument_type( + next_arguments[0], + child_argument_type, + next_args + ) + if found_child and child_argument_type.name not in self._additional_arguments: + self._additional_arguments.append(child_argument_type.name) + + if found_child: + break + + if not found_child: + result = self._validate_argument_by_argument_type(next_arguments[0], argument_type, next_args) return result