Improved argument parsing
This commit is contained in:
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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 \
|
||||
|
Reference in New Issue
Block a user