diff --git a/src/cpl_cli/__init__.py b/src/cpl_cli/__init__.py index 283a11c1..108f6a91 100644 --- a/src/cpl_cli/__init__.py +++ b/src/cpl_cli/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -29,4 +29,4 @@ from .main import main from .startup import Startup VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/__init__.py b/src/cpl_cli/_templates/__init__.py index 8b1fd416..1a577981 100644 --- a/src/cpl_cli/_templates/__init__.py +++ b/src/cpl_cli/_templates/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/build/__init__.py b/src/cpl_cli/_templates/build/__init__.py index 6e99f636..cc514f85 100644 --- a/src/cpl_cli/_templates/build/__init__.py +++ b/src/cpl_cli/_templates/build/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.build' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/generate/__init__.py b/src/cpl_cli/_templates/generate/__init__.py index 85c86198..a9722bc8 100644 --- a/src/cpl_cli/_templates/generate/__init__.py +++ b/src/cpl_cli/_templates/generate/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.generate' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/__init__.py b/src/cpl_cli/_templates/new/__init__.py index 89efbf46..38908ef8 100644 --- a/src/cpl_cli/_templates/new/__init__.py +++ b/src/cpl_cli/_templates/new/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/console/__init__.py b/src/cpl_cli/_templates/new/console/__init__.py index 8f8455f7..157a7975 100644 --- a/src/cpl_cli/_templates/new/console/__init__.py +++ b/src/cpl_cli/_templates/new/console/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/console/source/__init__.py b/src/cpl_cli/_templates/new/console/source/__init__.py index 3a71ce79..e08841d1 100644 --- a/src/cpl_cli/_templates/new/console/source/__init__.py +++ b/src/cpl_cli/_templates/new/console/source/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/console/source/name/__init__.py b/src/cpl_cli/_templates/new/console/source/name/__init__.py index 14611e2c..40d1c457 100644 --- a/src/cpl_cli/_templates/new/console/source/name/__init__.py +++ b/src/cpl_cli/_templates/new/console/source/name/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.name' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/console/source/tests/__init__.py b/src/cpl_cli/_templates/new/console/source/tests/__init__.py index 38d68d91..de601885 100644 --- a/src/cpl_cli/_templates/new/console/source/tests/__init__.py +++ b/src/cpl_cli/_templates/new/console/source/tests/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.tests' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/library/__init__.py b/src/cpl_cli/_templates/new/library/__init__.py index c0ee86ea..381c2206 100644 --- a/src/cpl_cli/_templates/new/library/__init__.py +++ b/src/cpl_cli/_templates/new/library/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/library/source/__init__.py b/src/cpl_cli/_templates/new/library/source/__init__.py index 8611f624..08cd2bba 100644 --- a/src/cpl_cli/_templates/new/library/source/__init__.py +++ b/src/cpl_cli/_templates/new/library/source/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/library/source/name/__init__.py b/src/cpl_cli/_templates/new/library/source/name/__init__.py index 9b6f5be1..6639964c 100644 --- a/src/cpl_cli/_templates/new/library/source/name/__init__.py +++ b/src/cpl_cli/_templates/new/library/source/name/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.name' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/new/library/source/tests/__init__.py b/src/cpl_cli/_templates/new/library/source/tests/__init__.py index cd64ce74..82ffff0a 100644 --- a/src/cpl_cli/_templates/new/library/source/tests/__init__.py +++ b/src/cpl_cli/_templates/new/library/source/tests/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.tests' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/_templates/publish/__init__.py b/src/cpl_cli/_templates/publish/__init__.py index c1dc353c..3c6a39a4 100644 --- a/src/cpl_cli/_templates/publish/__init__.py +++ b/src/cpl_cli/_templates/publish/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.publish' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index a373778d..9a833a86 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -3,7 +3,6 @@ import sys from typing import Optional from cpl_core.application.application_abc import ApplicationABC -from cpl_core.configuration.console_argument import ConsoleArgument from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.console.console import Console from cpl_core.dependency_injection import ServiceProviderABC diff --git a/src/cpl_cli/command/__init__.py b/src/cpl_cli/command/__init__.py index e993d293..f048ccca 100644 --- a/src/cpl_cli/command/__init__.py +++ b/src/cpl_cli/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -28,4 +28,4 @@ from .publish_service import PublishService from .version_service import VersionService VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/configuration/__init__.py b/src/cpl_cli/configuration/__init__.py index b170c452..bf21d2d4 100644 --- a/src/cpl_cli/configuration/__init__.py +++ b/src/cpl_cli/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -30,4 +30,4 @@ from .workspace_settings import WorkspaceSettings from .workspace_settings_name_enum import WorkspaceSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/cpl_cli.json b/src/cpl_cli/cpl_cli.json index c543514f..e895b319 100644 --- a/src/cpl_cli/cpl_cli.json +++ b/src/cpl_cli/cpl_cli.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "1" + "Micro": "3.dev2" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,7 +16,7 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.6.2" + "cpl-core>=2022.6.3.dev2" ], "PythonVersion": ">=3.10", "PythonPath": {}, diff --git a/src/cpl_cli/live_server/__init__.py b/src/cpl_cli/live_server/__init__.py index 199a7712..b46d0bf5 100644 --- a/src/cpl_cli/live_server/__init__.py +++ b/src/cpl_cli/live_server/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/publish/__init__.py b/src/cpl_cli/publish/__init__.py index 0b194ade..1fb15959 100644 --- a/src/cpl_cli/publish/__init__.py +++ b/src/cpl_cli/publish/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -24,4 +24,4 @@ from .publisher_abc import PublisherABC from .publisher_service import PublisherService VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/source_creator/__init__.py b/src/cpl_cli/source_creator/__init__.py index 1f86e0c5..8bc73e83 100644 --- a/src/cpl_cli/source_creator/__init__.py +++ b/src/cpl_cli/source_creator/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.source_creator' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.1' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='1') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py index e3a67712..8243cfdc 100644 --- a/src/cpl_cli/startup.py +++ b/src/cpl_cli/startup.py @@ -2,7 +2,7 @@ import os from typing import Optional from cpl_core.application.startup_abc import StartupABC -from cpl_core.configuration.console_argument import ConsoleArgument +from cpl_core.configuration.argument_abc import ConsoleArgument from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC @@ -80,7 +80,7 @@ class Startup(StartupABC): configuration.add_console_argument( ConsoleArgument('', script, [], ' ', is_value_token_optional=True)) - configuration.add_console_arguments(error=False) + configuration.parse_console_arguments(error=False) return configuration diff --git a/src/cpl_core/__init__.py b/src/cpl_core/__init__.py index e741b291..0c5f97cc 100644 --- a/src/cpl_core/__init__.py +++ b/src/cpl_core/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/application/__init__.py b/src/cpl_core/application/__init__.py index 155bb71f..fd655602 100644 --- a/src/cpl_core/application/__init__.py +++ b/src/cpl_core/application/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.application' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -27,4 +27,4 @@ from .startup_abc import StartupABC from .startup_extension_abc import StartupExtensionABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/application/application_builder.py b/src/cpl_core/application/application_builder.py index c879ae69..e2e53a1d 100644 --- a/src/cpl_core/application/application_builder.py +++ b/src/cpl_core/application/application_builder.py @@ -55,6 +55,7 @@ class ApplicationBuilder(ApplicationBuilderABC): config = self._configuration services = self._services.build_service_provider() config.resolve_runnable_argument_types(services) + config.parse_console_arguments(error=False) for ex in self._app_extensions: extension = ex() diff --git a/src/cpl_core/configuration/__init__.py b/src/cpl_core/configuration/__init__.py index de358f22..07c9bc68 100644 --- a/src/cpl_core/configuration/__init__.py +++ b/src/cpl_core/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -24,7 +24,7 @@ from .configuration import Configuration from .configuration_abc import ConfigurationABC from .configuration_model_abc import ConfigurationModelABC from .configuration_variable_name_enum import ConfigurationVariableNameEnum -from .console_argument import ConsoleArgument +from .argument_abc import ArgumentABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/configuration/argument_abc.py b/src/cpl_core/configuration/argument_abc.py new file mode 100644 index 00000000..6dab1ec3 --- /dev/null +++ b/src/cpl_core/configuration/argument_abc.py @@ -0,0 +1,60 @@ +from abc import ABC, abstractmethod + +from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum + + +class ArgumentABC(ABC): + + @abstractmethod + def __init__(self, + token: str, + name: str, + aliases: list[str], + console_arguments: list['ArgumentABC'] = None + ): + r"""Representation of an console argument + + Parameter + --------- + token: :class:`str` + name: :class:`str` + aliases: list[:class:`str`] + console_arguments: List[:class:`cpl_core.configuration.console_argument.ConsoleArgument`] + """ + self._token = token + self._name = name + self._aliases = aliases + self._console_arguments = console_arguments if console_arguments is not None else [] + + @property + def token(self) -> str: + return self._token + + @property + def name(self) -> str: + return self._name + + @property + def aliases(self) -> list[str]: + return self._aliases + + @property + def console_arguments(self) -> list['ArgumentABC']: + return self._console_arguments + + def add_console_argument(self, arg_type: ArgumentTypeEnum, *args, **kwargs) -> 'ArgumentABC': + r"""Creates and adds a console argument to known console arguments + + Parameter + --------- + arg_type: :class:`str` + Specifies the specific type of the argument + + Returns + ------ + self :class:`cpl_core.configuration.console_argument.ConsoleArgument` not created argument! + """ + from cpl_core.configuration.argument_builder import ArgumentBuilder + argument = ArgumentBuilder.build_argument(arg_type, *args, *kwargs) + self._console_arguments.append(argument) + return self diff --git a/src/cpl_core/configuration/argument_builder.py b/src/cpl_core/configuration/argument_builder.py new file mode 100644 index 00000000..9d797d76 --- /dev/null +++ b/src/cpl_core/configuration/argument_builder.py @@ -0,0 +1,30 @@ +from typing import Union + +from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum +from cpl_core.configuration.executable_argument import ExecutableArgument +from cpl_core.configuration.flag_argument import FlagArgument +from cpl_core.configuration.variable_argument import VariableArgument +from cpl_core.console import Console + + +class ArgumentBuilder: + + @staticmethod + def build_argument(arg_type: ArgumentTypeEnum, *args, **kwargs) -> Union[ + ExecutableArgument, FlagArgument, VariableArgument]: + argument = None + try: + match arg_type: + case ArgumentTypeEnum.Flag: + argument = FlagArgument(*args, **kwargs) + case ArgumentTypeEnum.Executable: + argument = ExecutableArgument(*args, **kwargs) + case ArgumentTypeEnum.Variable: + argument = VariableArgument(*args, **kwargs) + case _: + Console.error('Invalid argument type') + Console.close() + except TypeError as e: + Console.error(str(e)) + Console.close() + return argument diff --git a/src/cpl_core/configuration/runnable_argument_abc.py b/src/cpl_core/configuration/argument_executable_abc.py similarity index 81% rename from src/cpl_core/configuration/runnable_argument_abc.py rename to src/cpl_core/configuration/argument_executable_abc.py index ae1a7c25..d7f3319a 100644 --- a/src/cpl_core/configuration/runnable_argument_abc.py +++ b/src/cpl_core/configuration/argument_executable_abc.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod -class RunnableArgumentABC(ABC): +class ArgumentExecutableABC(ABC): @abstractmethod def __init__(self): pass diff --git a/src/cpl_core/configuration/argument_type_enum.py b/src/cpl_core/configuration/argument_type_enum.py new file mode 100644 index 00000000..d8acc8fb --- /dev/null +++ b/src/cpl_core/configuration/argument_type_enum.py @@ -0,0 +1,8 @@ +from enum import Enum + + +class ArgumentTypeEnum(Enum): + + Flag = 0 + Executable = 1 + Variable = 3 diff --git a/src/cpl_core/configuration/configuration.py b/src/cpl_core/configuration/configuration.py index 573793bb..1fa0fb1f 100644 --- a/src/cpl_core/configuration/configuration.py +++ b/src/cpl_core/configuration/configuration.py @@ -4,11 +4,15 @@ import sys from collections.abc import Callable from typing import Union, Type, Optional +from cpl_core.configuration.argument_abc import ArgumentABC +from cpl_core.configuration.argument_builder import ArgumentBuilder +from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_variable_name_enum import ConfigurationVariableNameEnum -from cpl_core.configuration.console_argument import ConsoleArgument -from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC +from cpl_core.configuration.executable_argument import ExecutableArgument +from cpl_core.configuration.flag_argument import FlagArgument +from cpl_core.configuration.variable_argument import VariableArgument from cpl_core.console.console import Console from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.dependency_injection import ServiceProviderABC @@ -26,7 +30,7 @@ class Configuration(ConfigurationABC): self._application_environment = ApplicationEnvironment() self._config: dict[Union[type, str], Union[ConfigurationModelABC, str]] = {} - self._argument_types: list[ConsoleArgument] = [] + self._argument_types: list[ArgumentABC] = [] self._additional_arguments: list[str] = [] self._argument_error_function: Optional[Callable] = None @@ -116,155 +120,6 @@ class Configuration(ConfigurationABC): else: self._config[name] = value - def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument, - next_arguments: list[str] = None) -> bool: - r"""Validate argument by argument type - - Parameter - --------- - argument: :class:`str` - Command as string - argument_type: :class:`cpl_core.configuration.console_argument.ConsoleArgument` - Command type as ConsoleArgument - next_arguments: list[:class:`str`] - Following arguments of argument - - Returns - ------- - Object of :class:`bool` - - Raises - ------ - Exception: An error occurred getting an argument for a command - """ - argument_name = '' - value = '' - result = False - - if argument_type.value_token != '' and argument_type.value_token in argument: - # ?new=value - found = False - for alias in argument_type.aliases: - if alias in argument: - found = True - - if argument_type.name not in argument_name and not found: - return False - - if argument_type.is_value_token_optional is not None and argument_type.is_value_token_optional: - if argument_type.name not in self._additional_arguments: - self._additional_arguments.append(argument_type.name) - result = True - - 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.value_token)[1] - - if argument_name == '': - raise Exception(f'Expected argument for command: {argument_type.name}') - - result = True - - if argument_type.is_value_token_optional is True: - is_valid = False - - name_list = argument.split(argument_type.token) - if len(name_list) > 1: - value_list = name_list[1].split(argument_type.value_token) - if len(value_list) > 1: - is_valid = True - value = argument.split(argument_type.token)[1].split(argument_type.value_token)[1] - - if not is_valid: - if argument_type.name not in self._additional_arguments: - self._additional_arguments.append(argument_type.name) - result = True - else: - value = argument.split(argument_type.token)[1].split(argument_type.value_token)[1] - - if argument_name != argument_type.name and argument_name not in argument_type.aliases: - return False - - self._set_variable(argument_type.name, value) - result = True - - elif argument_type.value_token == ' ': - # ?new value - found = False - for alias in argument_type.aliases: - if alias == argument or f' {alias} ' == argument: - found = True - - if (argument_type.token != '' and f'{argument_type.token}{argument_type.name}' != argument - or argument_type.name not in argument) and not found: - return False - - if (next_arguments is None or len(next_arguments) == 0) and \ - argument_type.is_value_token_optional is not True: - 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 = '' - else: - value = next_arguments[0] - # next_arguments.remove(value) - self._handled_args.append(value) - - if argument_type.token != '' and argument.startswith(argument_type.token): - # --new value - argument_name = argument.split(argument_type.token)[1] - else: - # new value - argument_name = argument - - if argument_name != argument_type.name and argument_name not in argument_type.aliases: - return False - - if value == '': - if argument_type.name not in self._additional_arguments: - self._additional_arguments.append(argument_type.name) - else: - self._set_variable(argument_type.name, value) - - result = True - - elif argument_type.name == argument or argument in argument_type.aliases: - # new - self._additional_arguments.append(argument_type.name) - result = True - - if result: - self._handled_args.append(argument) - if next_arguments is not None and len(next_arguments) > 0: - next_args = [] - if len(next_arguments) > 1: - next_args = next_arguments[1:] - - 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 - def _load_json_file(self, file: str, output: bool) -> dict: r"""Reads the json file @@ -298,51 +153,65 @@ class Configuration(ConfigurationABC): if var_name in [key.upper() for key in os.environ.keys()]: self._set_variable(variable, os.environ[var_name]) - def add_console_argument(self, argument: ConsoleArgument): + def add_console_argument(self, argument: ArgumentABC): self._argument_types.append(argument) - def add_console_arguments(self, error: bool = None): - for arg_name in ConfigurationVariableNameEnum.to_list(): - self.add_console_argument(ConsoleArgument('--', str(arg_name).upper(), [str(arg_name).lower()], '=')) - - arg_list = sys.argv[1:] + def _parse_arguments(self, call_stack: list[Callable], arg_list: list[str], args_types: list[ArgumentABC]): for i in range(0, len(arg_list)): - argument = arg_list[i] - next_arguments = [] - error_message = '' + arg_str = arg_list[i] + Console.write_line('ARG_STR', arg_str) + for arg in args_types: + Console.write_line('ARG', arg.name, type(arg), len(arg.console_arguments)) + arg_str_without_token = arg_str + if arg.token != "" and arg.token in arg_str: + arg_str_without_token = arg_str.split(arg.token)[1] - if argument in self._handled_args: - break + # executable + if isinstance(arg, ExecutableArgument): + if arg_str.startswith(arg.token) \ + and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases: + Console.write_line('EXEC', arg.name) + call_stack.append(arg.run) + self._parse_arguments(call_stack, arg_list[i:], arg.console_arguments) - if i + 1 < len(arg_list): - next_arguments = arg_list[i + 1:] + # variables + elif isinstance(arg, VariableArgument): + arg_str_without_value = arg_str_without_token + if arg.value_token in arg_str_without_value: + arg_str_without_value = arg_str_without_token.split(arg.value_token)[0] - found = False - for argument_type in self._argument_types: - try: - found = self._validate_argument_by_argument_type(argument, argument_type, next_arguments) - if found: - break - except Exception as e: - error_message = e + if arg_str.startswith(arg.token) \ + and arg_str_without_value == arg.name or arg_str_without_value in arg.aliases: + if arg.value_token != ' ': + value = arg_str_without_token.split(arg.value_token)[1] + else: + value = arg_list[i + 1] + self._set_variable(arg.name, value) + self._parse_arguments(call_stack, arg_list[i + 1:], arg.console_arguments) + # flags + elif isinstance(arg, FlagArgument): + if arg_str.startswith(arg.token) \ + and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases: + self._additional_arguments.append(arg.name) + self._parse_arguments(call_stack, arg_list[i + 1:], arg.console_arguments) - if not found and error_message == '' and error is not False: - error_message = f'Invalid argument: {argument}' + Console.write_line() - if error_message != '': - if self._argument_error_function is not None: - self._argument_error_function(error_message) - else: - self._print_error(__name__, error_message) + def parse_console_arguments(self, error: bool = None): + # sets environment variables as possible arguments as: --VAR=VALUE + for arg_name in ConfigurationVariableNameEnum.to_list(): + self.add_console_argument(VariableArgument('--', str(arg_name).upper(), [str(arg_name).lower()], '=')) - sys.exit() + Console.error('Parsing arguments:') + arg_list = sys.argv[1:] + call_stack = [] + self._parse_arguments(call_stack, arg_list, self._argument_types) - add_args = [] - for next_arg in next_arguments: - if next_arg not in self._handled_args and next_arg not in self._additional_arguments: - add_args.append(next_arg) + Console.error('Parsing finished') - self._set_variable(f'{argument}AdditionalArguments', add_args) + for call in call_stack: + Console.write_line(call) + call(self._additional_arguments) def add_json_file(self, name: str, optional: bool = None, output: bool = True, path: str = None): if os.path.isabs(name): @@ -380,11 +249,10 @@ class Configuration(ConfigurationABC): def add_configuration(self, key_type: Union[str, type], value: ConfigurationModelABC): self._config[key_type] = value - def create_console_argument(self, token: str, name: str, aliases: list[str], value_token: str, - is_value_token_optional: bool = None, - runnable: Type[RunnableArgumentABC] = None) -> ConsoleArgument: - argument = ConsoleArgument(token, name, aliases, value_token, is_value_token_optional, runnable) - self.add_console_argument(argument) + def create_console_argument(self, arg_type: ArgumentTypeEnum, token: str, name: str, aliases: list[str], + *args, **kwargs) -> ArgumentABC: + argument = ArgumentBuilder.build_argument(arg_type, token, name, aliases, *args, *kwargs) + self._argument_types.append(argument) return argument def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> \ @@ -408,4 +276,5 @@ class Configuration(ConfigurationABC): def resolve_runnable_argument_types(self, services: ServiceProviderABC): for arg in self._argument_types: - arg.set_runnable(services.get_service(arg.runnable_type)) + if isinstance(arg, ExecutableArgument): + arg.set_executable(services.get_service(arg.executable_type)) diff --git a/src/cpl_core/configuration/configuration_abc.py b/src/cpl_core/configuration/configuration_abc.py index 5307f924..a2a9c48a 100644 --- a/src/cpl_core/configuration/configuration_abc.py +++ b/src/cpl_core/configuration/configuration_abc.py @@ -2,9 +2,9 @@ from abc import abstractmethod, ABC from collections.abc import Callable from typing import Type, Union, Optional -from cpl_core.configuration.console_argument import ConsoleArgument from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC -from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC +from cpl_core.configuration.argument_abc import ArgumentABC +from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC @@ -43,18 +43,18 @@ class ConfigurationABC(ABC): pass @abstractmethod - def add_console_argument(self, argument: ConsoleArgument): + def add_console_argument(self, argument: ArgumentABC): r"""Adds console argument to known console arguments Parameter --------- - argument: :class:`cpl_core.configuration.console_argument.ConsoleArgument` + argument: :class:`cpl_core.configuration.console_argument.ConsoleArgumentABC` Specifies the console argument """ pass @abstractmethod - def add_console_arguments(self, error: bool = None): + def parse_console_arguments(self, error: bool = None): r"""Reads the console arguments Parameter @@ -95,9 +95,8 @@ class ConfigurationABC(ABC): pass @abstractmethod - def create_console_argument(self, token: str, name: str, aliases: list[str], value_token: str, - is_value_token_optional: bool = None, - runnable: Type[RunnableArgumentABC] = None) -> ConsoleArgument: + def create_console_argument(self, arg_type: ArgumentTypeEnum, token: str, name: str, aliases: list[str], + *args, **kwargs) -> ArgumentABC: r"""Creates and adds a console argument to known console arguments Parameter @@ -112,12 +111,12 @@ class ConfigurationABC(ABC): Specifies were the value begins is_value_token_optional :class:`bool` Specifies if values are optional - runnable: :class:`cpl_core.configuration.console_argument.ConsoleArgument` + runnable: :class:`cpl_core.configuration.console_argument.ConsoleArgumentABC` Specifies class to run when called if value is not None Returns ------ - Object of :class:`cpl_core.configuration.console_argument.ConsoleArgument` + Object of :class:`cpl_core.configuration.console_argument.ConsoleArgumentABC` """ pass diff --git a/src/cpl_core/configuration/console_argument.py b/src/cpl_core/configuration/console_argument.py deleted file mode 100644 index 5508d73a..00000000 --- a/src/cpl_core/configuration/console_argument.py +++ /dev/null @@ -1,99 +0,0 @@ -from typing import Type, Optional - -from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC - - -class ConsoleArgument: - - def __init__(self, - token: str, - name: str, - aliases: list[str], - value_token: str, - is_value_token_optional: bool = None, - runnable: Type[RunnableArgumentABC] = None, - console_arguments: list['ConsoleArgument'] = None - ): - r"""Representation of an console argument - - Parameter - --------- - token: :class:`str` - name: :class:`str` - aliases: list[:class:`str`] - value_token: :class:`str` - is_value_token_optional: :class:`bool` - runnable: :class:`cpl_core.configuration.console_argument.ConsoleArgument` - console_arguments: List[:class:`cpl_core.configuration.console_argument.ConsoleArgument`] - """ - self._token = token - self._name = name - self._aliases = aliases - self._value_token = value_token - self._is_value_token_optional = is_value_token_optional - self._console_arguments = console_arguments if console_arguments is not None else [] - self._runnable_type = runnable - self._runnable: Optional[RunnableArgumentABC] = None - - @property - def token(self) -> str: - return self._token - - @property - def name(self) -> str: - return self._name - - @property - def aliases(self) -> list[str]: - return self._aliases - - @property - def value_token(self) -> str: - return self._value_token - - @property - def is_value_token_optional(self) -> bool: - return self._is_value_token_optional - - @property - def console_arguments(self) -> list['ConsoleArgument']: - return self._console_arguments - - @property - def runnable_type(self) -> Type[RunnableArgumentABC]: - return self._runnable_type - - def set_runnable(self, runnable: RunnableArgumentABC): - self._runnable = runnable - - def add_console_argument(self, token: str, name: str, aliases: list[str], value_token: str, - is_value_token_optional: bool = None) -> 'ConsoleArgument': - r"""Creates and adds a console argument to known console arguments - - Parameter - --------- - token: :class:`str` - Specifies optional beginning of argument - name :class:`str` - Specifies name of argument - aliases list[:class:`str`] - Specifies possible aliases of name - value_token :class:`str` - Specifies were the value begins - is_value_token_optional :class:`bool` - Specifies if values are optional - - Returns - ------ - self :class:`cpl_core.configuration.console_argument.ConsoleArgument` not created argument! - """ - argument = ConsoleArgument(token, name, aliases, value_token, is_value_token_optional) - self._console_arguments.append(argument) - return self - - def run(self, args: list[str]): - r"""Executes runnable if exists - """ - if self._runnable is None: - return - self._runnable.run(args) diff --git a/src/cpl_core/configuration/executable_argument.py b/src/cpl_core/configuration/executable_argument.py new file mode 100644 index 00000000..a9d512d4 --- /dev/null +++ b/src/cpl_core/configuration/executable_argument.py @@ -0,0 +1,34 @@ +from typing import Type, Optional + +from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC +from cpl_core.configuration.argument_abc import ArgumentABC + + +class ExecutableArgument(ArgumentABC): + + def __init__(self, + token: str, + name: str, + aliases: list[str], + executable: Type[ArgumentExecutableABC], + console_arguments: list['ArgumentABC'] = None + ): + + self._executable_type = executable + self._executable: Optional[ArgumentExecutableABC] = None + + ArgumentABC.__init__(self, token, name, aliases, console_arguments) + + @property + def executable_type(self) -> type: + return self._executable_type + + def set_executable(self, executable: ArgumentExecutableABC): + self._executable = executable + + def run(self, args: list[str]): + r"""Executes runnable if exists + """ + if self._executable is None: + return + self._executable.run(args) diff --git a/src/cpl_core/configuration/flag_argument.py b/src/cpl_core/configuration/flag_argument.py new file mode 100644 index 00000000..0d57af2a --- /dev/null +++ b/src/cpl_core/configuration/flag_argument.py @@ -0,0 +1,13 @@ +from cpl_core.configuration.argument_abc import ArgumentABC + + +class FlagArgument(ArgumentABC): + + def __init__(self, + token: str, + name: str, + aliases: list[str], + console_arguments: list['ArgumentABC'] = None + ): + + ArgumentABC.__init__(self, token, name, aliases, console_arguments) diff --git a/src/cpl_core/configuration/variable_argument.py b/src/cpl_core/configuration/variable_argument.py new file mode 100644 index 00000000..bcf7b0cc --- /dev/null +++ b/src/cpl_core/configuration/variable_argument.py @@ -0,0 +1,27 @@ +from cpl_core.configuration.argument_abc import ArgumentABC + + +class VariableArgument(ArgumentABC): + + def __init__(self, + token: str, + name: str, + aliases: list[str], + value_token: str, + console_arguments: list['ArgumentABC'] = None + ): + self._value_token = value_token + self._value: str = '' + + ArgumentABC.__init__(self, token, name, aliases, console_arguments) + + @property + def value_token(self) -> str: + return self._value_token + + @property + def value(self) -> str: + return self._value + + def set_value(self, value: str): + self._value = value diff --git a/src/cpl_core/console/__init__.py b/src/cpl_core/console/__init__.py index 928c0904..6d11770b 100644 --- a/src/cpl_core/console/__init__.py +++ b/src/cpl_core/console/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.console' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum from .spinner_thread import SpinnerThread VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/cpl_core.json b/src/cpl_core/cpl_core.json index e171d838..7da4887e 100644 --- a/src/cpl_core/cpl_core.json +++ b/src/cpl_core/cpl_core.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "2" + "Micro": "3.dev1" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_core/database/__init__.py b/src/cpl_core/database/__init__.py index 55bc3f3c..a161bac8 100644 --- a/src/cpl_core/database/__init__.py +++ b/src/cpl_core/database/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings from .table_abc import TableABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/database/connection/__init__.py b/src/cpl_core/database/connection/__init__.py index accbfaa6..1e918064 100644 --- a/src/cpl_core/database/connection/__init__.py +++ b/src/cpl_core/database/connection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection from .database_connection_abc import DatabaseConnectionABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/database/context/__init__.py b/src/cpl_core/database/context/__init__.py index e1684eea..c9d40b13 100644 --- a/src/cpl_core/database/context/__init__.py +++ b/src/cpl_core/database/context/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -24,4 +24,4 @@ from .database_context import DatabaseContext from .database_context_abc import DatabaseContextABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/dependency_injection/__init__.py b/src/cpl_core/dependency_injection/__init__.py index 044ec621..d9b831dd 100644 --- a/src/cpl_core/dependency_injection/__init__.py +++ b/src/cpl_core/dependency_injection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -28,4 +28,4 @@ from .service_provider import ServiceProvider from .service_provider_abc import ServiceProviderABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index a1535f98..39f298b7 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -34,7 +34,7 @@ class ServiceProvider(ServiceProviderABC): self._database_context = db_context self._scope: Optional[ScopeABC] = None - def _find_service(self, service_type: type) -> ServiceDescriptor: + def _find_service(self, service_type: type) -> Optional[ServiceDescriptor]: for descriptor in self._service_descriptors: if descriptor.service_type == service_type or issubclass(descriptor.service_type, service_type): return descriptor diff --git a/src/cpl_core/environment/__init__.py b/src/cpl_core/environment/__init__.py index 3c96a3bf..890cd7e7 100644 --- a/src/cpl_core/environment/__init__.py +++ b/src/cpl_core/environment/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum from .application_environment import ApplicationEnvironment VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/logging/__init__.py b/src/cpl_core/logging/__init__.py index 3e341963..481f3abd 100644 --- a/src/cpl_core/logging/__init__.py +++ b/src/cpl_core/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings from .logging_settings_name_enum import LoggingSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/mailing/__init__.py b/src/cpl_core/mailing/__init__.py index 0eeefc95..06162391 100644 --- a/src/cpl_core/mailing/__init__.py +++ b/src/cpl_core/mailing/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings from .email_client_settings_name_enum import EMailClientSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/time/__init__.py b/src/cpl_core/time/__init__.py index 4dea9c68..1bee00e0 100644 --- a/src/cpl_core/time/__init__.py +++ b/src/cpl_core/time/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.time' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/cpl_core/utils/__init__.py b/src/cpl_core/utils/__init__.py index 5d9e5653..f17cb23f 100644 --- a/src/cpl_core/utils/__init__.py +++ b/src/cpl_core/utils/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.6.2' +__version__ = '2022.6.3.dev2' from collections import namedtuple @@ -25,4 +25,4 @@ from .string import String from .pip import Pip VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='6', micro='2') +version_info = VersionInfo(major='2022', minor='6', micro='3.dev2') diff --git a/src/tests/custom/database/src/startup.py b/src/tests/custom/database/src/startup.py index 112c1ae4..9ceecabf 100644 --- a/src/tests/custom/database/src/startup.py +++ b/src/tests/custom/database/src/startup.py @@ -21,7 +21,7 @@ class Startup(StartupABC): def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC) -> ConfigurationABC: configuration.add_environment_variables('PYTHON_') configuration.add_environment_variables('CPL_') - configuration.add_console_arguments() + configuration.parse_console_arguments() configuration.add_json_file(f'appsettings.json') configuration.add_json_file(f'appsettings.{configuration.environment.environment_name}.json') configuration.add_json_file(f'appsettings.{configuration.environment.host_name}.json', optional=True) diff --git a/src/tests/custom/general/src/general/arguments/generate_argument.py b/src/tests/custom/general/src/general/arguments/generate_argument.py index da71112f..b6830b32 100644 --- a/src/tests/custom/general/src/general/arguments/generate_argument.py +++ b/src/tests/custom/general/src/general/arguments/generate_argument.py @@ -1,11 +1,18 @@ -from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC from cpl_core.console import Console +from cpl_core.environment import ApplicationEnvironmentABC -class GenerateArgument(RunnableArgumentABC): +class GenerateArgument(ArgumentExecutableABC): - def __init__(self): - RunnableArgumentABC.__init__(self) + def __init__(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + ArgumentExecutableABC.__init__(self) + self._config = config + self._env = env def run(self, args: list[str]): - Console.write_line('Generate:', args) + Console.error('Generate:') + for c in self._config._config: + Console.write_line(c, self._config.get_configuration(c)) + Console.write_line(args, self._env.environment_name) diff --git a/src/tests/custom/general/src/general/arguments/install_argument.py b/src/tests/custom/general/src/general/arguments/install_argument.py index 8f62c3b7..aca00937 100644 --- a/src/tests/custom/general/src/general/arguments/install_argument.py +++ b/src/tests/custom/general/src/general/arguments/install_argument.py @@ -1,11 +1,11 @@ -from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC +from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC from cpl_core.console import Console -class InstallArgument(RunnableArgumentABC): +class InstallArgument(ArgumentExecutableABC): def __init__(self): - RunnableArgumentABC.__init__(self) + ArgumentExecutableABC.__init__(self) def run(self, args: list[str]): Console.write_line('Install:', args) diff --git a/src/tests/custom/general/src/general/parameter_startup.py b/src/tests/custom/general/src/general/parameter_startup.py index 629f1758..f28791a1 100644 --- a/src/tests/custom/general/src/general/parameter_startup.py +++ b/src/tests/custom/general/src/general/parameter_startup.py @@ -1,5 +1,6 @@ from cpl_core.application import StartupExtensionABC from cpl_core.configuration import ConfigurationABC +from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.environment import ApplicationEnvironmentABC from arguments.generate_argument import GenerateArgument @@ -12,18 +13,18 @@ class ParameterStartup(StartupExtensionABC): StartupExtensionABC.__init__(self) def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): - config.create_console_argument('', 'generate', ['g', 'G'], '', runnable=GenerateArgument) \ - .add_console_argument('', 'abc', ['a', 'A'], ' ') \ - .add_console_argument('', 'class', ['c', 'C'], ' ') \ - .add_console_argument('', 'enum', ['e', 'E'], ' ') \ - .add_console_argument('', 'service', ['s', 'S'], ' ') \ - .add_console_argument('', 'settings', ['st', 'ST'], ' ') \ - .add_console_argument('', 'thread', ['t', 'T'], ' ') \ - .add_console_argument('-', 'o', ['o', 'O'], '=') - config.create_console_argument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True, - runnable=InstallArgument) \ - .add_console_argument('--', 'virtual', ['v', 'V'], '') \ - .add_console_argument('--', 'simulate', ['s', 'S'], '') + config.create_console_argument(ArgumentTypeEnum.Executable, '', 'generate', ['g', 'G'], GenerateArgument) \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '-', 'o', ['o', 'O'], '=') \ + .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) + config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallArgument) \ + .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \ + .add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services \