diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index baf1d082..fb12a920 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -22,13 +22,14 @@
-
-
+
-
-
+
+
+
+
@@ -100,7 +101,7 @@
-
+
@@ -489,13 +490,6 @@
1605881914521
-
- 1608048544558
-
-
-
- 1608048544558
-
1608049672925
@@ -832,7 +826,14 @@
1614797335732
-
+
+ 1614836560513
+
+
+
+ 1614836560514
+
+
@@ -848,7 +849,6 @@
-
@@ -873,7 +873,8 @@
-
+
+
diff --git a/src/cpl/application/application_abc.py b/src/cpl/application/application_abc.py
index 1f689092..d680c542 100644
--- a/src/cpl/application/application_abc.py
+++ b/src/cpl/application/application_abc.py
@@ -1,4 +1,3 @@
-import atexit
from abc import ABC, abstractmethod
from typing import Type, Optional
@@ -21,10 +20,6 @@ class ApplicationABC(ABC):
def use_startup(self, startup: Type[StartupABC]):
self._startup = startup()
- @staticmethod
- def output_at_exit():
- atexit.register(Console.close)
-
def build(self):
if self._startup is not None:
self._app_host = self._startup.create_application_host()
diff --git a/src/cpl/application/application_host.py b/src/cpl/application/application_host.py
index a7fb0659..d6f75cd0 100644
--- a/src/cpl/application/application_host.py
+++ b/src/cpl/application/application_host.py
@@ -1,3 +1,5 @@
+import atexit
+from collections import Callable
from datetime import datetime
from cpl.application.application_host_abc import ApplicationHostABC
@@ -5,6 +7,7 @@ from cpl.application.application_runtime import ApplicationRuntime
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration import Configuration
from cpl.configuration.configuration_abc import ConfigurationABC
+from cpl.console.console import Console
from cpl.dependency_injection.service_provider import ServiceProvider
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
@@ -35,4 +38,9 @@ class ApplicationHost(ApplicationHostABC):
def services(self) -> ServiceProviderABC:
return self._services
- def create(self): pass
+ @staticmethod
+ def output_at_exit():
+ atexit.register(Console.close)
+
+ def console_argument_error_function(self, function: Callable):
+ self._config.argument_error_function = function
diff --git a/src/cpl/application/application_host_abc.py b/src/cpl/application/application_host_abc.py
index 67016342..a9430915 100644
--- a/src/cpl/application/application_host_abc.py
+++ b/src/cpl/application/application_host_abc.py
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
+from collections import Callable
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC
@@ -21,3 +22,10 @@ class ApplicationHostABC(ABC):
@property
@abstractmethod
def services(self) -> ServiceProviderABC: pass
+
+ @staticmethod
+ @abstractmethod
+ def output_at_exit(): pass
+
+ @abstractmethod
+ def console_argument_error_function(self, function: Callable): pass
diff --git a/src/cpl/configuration/configuration.py b/src/cpl/configuration/configuration.py
index f8226aa8..dea89322 100644
--- a/src/cpl/configuration/configuration.py
+++ b/src/cpl/configuration/configuration.py
@@ -2,7 +2,7 @@ import json
import os
import sys
from collections import Callable
-from typing import Union, Type
+from typing import Union, Type, Optional
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
@@ -26,6 +26,8 @@ class Configuration(ConfigurationABC):
self._argument_types: list[ConsoleArgument] = []
self._additional_arguments: list[str] = []
+ self._argument_error_function: Optional[Callable] = None
+
@property
def environment(self) -> EnvironmentABC:
return self._hosting_environment
@@ -34,6 +36,14 @@ class Configuration(ConfigurationABC):
def additional_arguments(self) -> list[str]:
return self._additional_arguments
+ @property
+ def argument_error_function(self) -> Optional[Callable]:
+ return self._argument_error_function
+
+ @argument_error_function.setter
+ def argument_error_function(self, argument_error_function: Callable):
+ self._argument_error_function = argument_error_function
+
@staticmethod
def _print_info(name: str, message: str):
Console.set_foreground_color(ForegroundColor.green)
@@ -106,10 +116,22 @@ class Configuration(ConfigurationABC):
break
if not is_done:
- self._print_error(__name__, f'Invalid argument: {arg}')
+ message = f'Invalid argument: {arg}'
+
+ if self._argument_error_function is not None:
+ self._argument_error_function(message)
+ else:
+ self._print_error(__name__, message)
+
exit()
except Exception as e:
- self._print_error(__name__, f'Invalid argument: {arg} -> {e}')
+ message = f'Invalid argument: {arg} -> {e}'
+
+ if self._argument_error_function is not None:
+ self._argument_error_function(message)
+ else:
+ self._print_error(__name__, message)
+
exit()
def add_json_file(self, name: str, optional: bool = None):
@@ -149,7 +171,8 @@ class Configuration(ConfigurationABC):
def add_configuration(self, key_type: type, value: ConfigurationModelABC):
self._config[key_type] = value
- def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[str, Callable[ConfigurationModelABC]]:
+ def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[
+ str, Callable[ConfigurationModelABC]]:
if search_type not in self._config:
raise Exception(f'Config model by type {search_type} not found')
diff --git a/src/cpl/configuration/configuration_abc.py b/src/cpl/configuration/configuration_abc.py
index 8cffc87b..a3bb5806 100644
--- a/src/cpl/configuration/configuration_abc.py
+++ b/src/cpl/configuration/configuration_abc.py
@@ -1,6 +1,6 @@
from abc import abstractmethod, ABC
from collections import Callable
-from typing import Type, Union
+from typing import Type, Union, Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.environment.environment_abc import EnvironmentABC
@@ -19,6 +19,14 @@ class ConfigurationABC(ABC):
@abstractmethod
def additional_arguments(self) -> list[str]: pass
+ @property
+ @abstractmethod
+ def argument_error_function(self) -> Optional[Callable]: pass
+
+ @argument_error_function.setter
+ @abstractmethod
+ def argument_error_function(self, argument_error_function: Callable): pass
+
@abstractmethod
def add_environment_variables(self, prefix: str): pass
diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py
index fea06926..8ceb1cfc 100644
--- a/src/cpl_cli/startup.py
+++ b/src/cpl_cli/startup.py
@@ -8,6 +8,7 @@ from cpl.dependency_injection.service_provider_base import ServiceProviderABC
from cpl_cli.command_handler import CommandHandler
from cpl_cli.commands.help import Help
from cpl_cli.commands.version import Version
+from cpl_cli.error import Error
class Startup(StartupABC):
@@ -23,6 +24,9 @@ class Startup(StartupABC):
self._app_host = ApplicationHost()
self._configuration = self._app_host.configuration
self._services = self._app_host.services
+
+ self._app_host.console_argument_error_function(Error.error)
+
return self._app_host
def create_configuration(self) -> ConfigurationABC: