2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
7 changed files with 73 additions and 26 deletions
Showing only changes of commit 960607a60d - Show all commits

View File

@ -22,13 +22,14 @@
<select /> <select />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Improved cli"> <list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Smaller bugfixes">
<change afterPath="$PROJECT_DIR$/src/cpl_cli/error.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl/application/application_abc.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_abc.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/cpl/application/application_abc.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_abc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl/application/application_host.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_host.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/cpl/application/application_host.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_host.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl_cli/cli.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl_cli/cli.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/cpl/application/application_host_abc.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_host_abc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl_cli/command_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl_cli/command_handler.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/cpl/configuration/configuration.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/configuration/configuration.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl/configuration/configuration_abc.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/configuration/configuration_abc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl_cli/startup.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl_cli/startup.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -100,7 +101,7 @@
<recent name="$PROJECT_DIR$/src/cpl/database" /> <recent name="$PROJECT_DIR$/src/cpl/database" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.cli help"> <component name="RunManager" selected="Python.main cli">
<configuration name="cli build" type="PythonConfigurationType" factoryName="Python"> <configuration name="cli build" type="PythonConfigurationType" factoryName="Python">
<module name="sh_common_py_lib" /> <module name="sh_common_py_lib" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -489,13 +490,6 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1605881914521</updated> <updated>1605881914521</updated>
</task> </task>
<task id="LOCAL-00040" summary="Improved publisher">
<created>1608048544558</created>
<option name="number" value="00040" />
<option name="presentableId" value="LOCAL-00040" />
<option name="project" value="LOCAL" />
<updated>1608048544558</updated>
</task>
<task id="LOCAL-00041" summary="Improved publisher"> <task id="LOCAL-00041" summary="Improved publisher">
<created>1608049672925</created> <created>1608049672925</created>
<option name="number" value="00041" /> <option name="number" value="00041" />
@ -832,7 +826,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1614797335732</updated> <updated>1614797335732</updated>
</task> </task>
<option name="localTasksCounter" value="89" /> <task id="LOCAL-00089" summary="Smaller bugfixes">
<created>1614836560513</created>
<option name="number" value="00089" />
<option name="presentableId" value="LOCAL-00089" />
<option name="project" value="LOCAL" />
<updated>1614836560514</updated>
</task>
<option name="localTasksCounter" value="90" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -848,7 +849,6 @@
<option name="oldMeFiltersMigrated" value="true" /> <option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="Improved service providing" />
<MESSAGE value="Added email client" /> <MESSAGE value="Added email client" />
<MESSAGE value="Published" /> <MESSAGE value="Published" />
<MESSAGE value="Improved publisher" /> <MESSAGE value="Improved publisher" />
@ -873,7 +873,8 @@
<MESSAGE value="Added version and help cli command" /> <MESSAGE value="Added version and help cli command" />
<MESSAGE value="Improved help command" /> <MESSAGE value="Improved help command" />
<MESSAGE value="Improved cli" /> <MESSAGE value="Improved cli" />
<option name="LAST_COMMIT_MESSAGE" value="Improved cli" /> <MESSAGE value="Smaller bugfixes" />
<option name="LAST_COMMIT_MESSAGE" value="Smaller bugfixes" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -1,4 +1,3 @@
import atexit
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Type, Optional from typing import Type, Optional
@ -21,10 +20,6 @@ class ApplicationABC(ABC):
def use_startup(self, startup: Type[StartupABC]): def use_startup(self, startup: Type[StartupABC]):
self._startup = startup() self._startup = startup()
@staticmethod
def output_at_exit():
atexit.register(Console.close)
def build(self): def build(self):
if self._startup is not None: if self._startup is not None:
self._app_host = self._startup.create_application_host() self._app_host = self._startup.create_application_host()

View File

@ -1,3 +1,5 @@
import atexit
from collections import Callable
from datetime import datetime from datetime import datetime
from cpl.application.application_host_abc import ApplicationHostABC 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.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration import Configuration from cpl.configuration.configuration import Configuration
from cpl.configuration.configuration_abc import ConfigurationABC 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 import ServiceProvider
from cpl.dependency_injection.service_provider_base import ServiceProviderABC from cpl.dependency_injection.service_provider_base import ServiceProviderABC
@ -35,4 +38,9 @@ class ApplicationHost(ApplicationHostABC):
def services(self) -> ServiceProviderABC: def services(self) -> ServiceProviderABC:
return self._services 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

View File

@ -1,4 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import Callable
from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
@ -21,3 +22,10 @@ class ApplicationHostABC(ABC):
@property @property
@abstractmethod @abstractmethod
def services(self) -> ServiceProviderABC: pass def services(self) -> ServiceProviderABC: pass
@staticmethod
@abstractmethod
def output_at_exit(): pass
@abstractmethod
def console_argument_error_function(self, function: Callable): pass

View File

@ -2,7 +2,7 @@ import json
import os import os
import sys import sys
from collections import Callable 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_abc import ConfigurationABC
from cpl.configuration.configuration_model_abc import ConfigurationModelABC from cpl.configuration.configuration_model_abc import ConfigurationModelABC
@ -26,6 +26,8 @@ class Configuration(ConfigurationABC):
self._argument_types: list[ConsoleArgument] = [] self._argument_types: list[ConsoleArgument] = []
self._additional_arguments: list[str] = [] self._additional_arguments: list[str] = []
self._argument_error_function: Optional[Callable] = None
@property @property
def environment(self) -> EnvironmentABC: def environment(self) -> EnvironmentABC:
return self._hosting_environment return self._hosting_environment
@ -34,6 +36,14 @@ class Configuration(ConfigurationABC):
def additional_arguments(self) -> list[str]: def additional_arguments(self) -> list[str]:
return self._additional_arguments 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 @staticmethod
def _print_info(name: str, message: str): def _print_info(name: str, message: str):
Console.set_foreground_color(ForegroundColor.green) Console.set_foreground_color(ForegroundColor.green)
@ -106,10 +116,22 @@ class Configuration(ConfigurationABC):
break break
if not is_done: 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() exit()
except Exception as e: 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() exit()
def add_json_file(self, name: str, optional: bool = None): 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): def add_configuration(self, key_type: type, value: ConfigurationModelABC):
self._config[key_type] = value 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: if search_type not in self._config:
raise Exception(f'Config model by type {search_type} not found') raise Exception(f'Config model by type {search_type} not found')

View File

@ -1,6 +1,6 @@
from abc import abstractmethod, ABC from abc import abstractmethod, ABC
from collections import Callable 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.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.environment.environment_abc import EnvironmentABC from cpl.environment.environment_abc import EnvironmentABC
@ -19,6 +19,14 @@ class ConfigurationABC(ABC):
@abstractmethod @abstractmethod
def additional_arguments(self) -> list[str]: pass 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 @abstractmethod
def add_environment_variables(self, prefix: str): pass def add_environment_variables(self, prefix: str): pass

View File

@ -8,6 +8,7 @@ from cpl.dependency_injection.service_provider_base import ServiceProviderABC
from cpl_cli.command_handler import CommandHandler from cpl_cli.command_handler import CommandHandler
from cpl_cli.commands.help import Help from cpl_cli.commands.help import Help
from cpl_cli.commands.version import Version from cpl_cli.commands.version import Version
from cpl_cli.error import Error
class Startup(StartupABC): class Startup(StartupABC):
@ -23,6 +24,9 @@ class Startup(StartupABC):
self._app_host = ApplicationHost() self._app_host = ApplicationHost()
self._configuration = self._app_host.configuration self._configuration = self._app_host.configuration
self._services = self._app_host.services self._services = self._app_host.services
self._app_host.console_argument_error_function(Error.error)
return self._app_host return self._app_host
def create_configuration(self) -> ConfigurationABC: def create_configuration(self) -> ConfigurationABC: