From b1165e169a56bb9e5e8281a3fd0e11ed381132b5 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 11 Apr 2021 11:42:48 +0200 Subject: [PATCH] Improved console argument value handling in configuration --- src/cpl/configuration/configuration.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cpl/configuration/configuration.py b/src/cpl/configuration/configuration.py index 907ad041..ce567f10 100644 --- a/src/cpl/configuration/configuration.py +++ b/src/cpl/configuration/configuration.py @@ -157,10 +157,16 @@ class Configuration(ConfigurationABC): if argument_type.token != '' and argument.startswith(argument_type.token): # --new=value + if len(argument.split(argument_type.token)[1].split(argument_type.value_token)) == 0: + raise Exception(f'Expected argument for command: {argument}') + argument_name = argument.split(argument_type.token)[1].split(argument_type.value_token)[0] else: # new=value - argument_name = argument.split(argument_type.token)[1] + argument_name = argument.split(argument_type.value_token)[1] + + if argument_name == '': + raise Exception(f'Expected argument for command: {argument_type.name}') result = True @@ -199,7 +205,7 @@ class Configuration(ConfigurationABC): if (next_arguments is None or len(next_arguments) == 0) and \ argument_type.is_value_token_optional is not True: - raise Exception(f'Invalid argument: {argument}') + raise Exception(f'Expected argument for command: {argument_type.name}') if (next_arguments is None or len(next_arguments) == 0) and argument_type.is_value_token_optional is True: value = '' @@ -277,6 +283,7 @@ class Configuration(ConfigurationABC): if not found and error_message == '' and error is not False: error_message = f'Invalid argument: {argument}' + if error_message != '': if self._argument_error_function is not None: self._argument_error_function(error_message) else: