Added logic to add CLI commands from external packages

This commit is contained in:
2022-05-22 18:32:34 +02:00
parent d11c56db03
commit dec4a45d98
8 changed files with 114 additions and 57 deletions

View File

@@ -7,4 +7,4 @@ class ArgumentExecutableABC(ABC):
def __init__(self): pass
@abstractmethod
def run(self, args: list[str]): pass
def execute(self, args: list[str]): pass

View File

@@ -274,18 +274,19 @@ class Configuration(ConfigurationABC):
if config_model == search_type:
return self._config[config_model]
def parse_console_arguments(self, services: ServiceProviderABC, error: bool = None):
def parse_console_arguments(self, services: ServiceProviderABC, error: bool = None) -> bool:
# 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()], '='))
success = False
try:
arg_list = sys.argv[1:]
executables: list[ExecutableArgument] = []
self._parse_arguments(executables, arg_list, self._argument_types)
except Exception as e:
Console.error('An error occurred while parsing arguments.')
exit()
sys.exit()
try:
prevent = False
@@ -309,5 +310,9 @@ class Configuration(ConfigurationABC):
self.add_configuration('ACTIVE_EXECUTABLE', exe.name)
cmd.execute(self._additional_arguments)
prevent = exe.prevent_next_executable
success = True
except Exception as e:
Console.error('An error occurred while executing arguments.')
sys.exit()
return success

View File

@@ -141,12 +141,16 @@ class ConfigurationABC(ABC):
pass
@abstractmethod
def parse_console_arguments(self, services: 'ServiceProviderABC', error: bool = None):
def parse_console_arguments(self, services: 'ServiceProviderABC', error: bool = None) -> bool:
r"""Reads the console arguments
Parameter
---------
error: :class:`bool`
Defines is invalid argument error will be shown or not
Returns
-------
Bool to specify if executables were executed or not.
"""
pass

View File

@@ -3,7 +3,6 @@ from typing import Type, Optional
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
from cpl_core.configuration.argument_abc import ArgumentABC
from cpl_core.configuration.validator_abc import ValidatorABC
from cpl_core.console import Console
class ExecutableArgument(ArgumentABC):
@@ -40,4 +39,4 @@ class ExecutableArgument(ArgumentABC):
"""
if self._executable is None:
return
self._executable.run(args)
self._executable.execute(args)