2021.4.1 #11
20
src/cpl_cli/cli.py
Normal file
20
src/cpl_cli/cli.py
Normal file
@ -0,0 +1,20 @@
|
||||
from cpl.application.application_abc import ApplicationABC
|
||||
from cpl.console.console import Console
|
||||
|
||||
|
||||
class CLI(ApplicationABC):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationABC.__init__(self)
|
||||
|
||||
def configure(self):
|
||||
if self._services is None:
|
||||
Console.error('Service provider is empty')
|
||||
exit()
|
||||
|
||||
if self._configuration is None:
|
||||
Console.error('Configuration is empty')
|
||||
exit()
|
||||
|
||||
def main(self):
|
||||
Console.write_line(self._configuration)
|
8
src/cpl_cli/main.py
Normal file
8
src/cpl_cli/main.py
Normal file
@ -0,0 +1,8 @@
|
||||
from cpl_cli.cli import CLI
|
||||
from cpl_cli.startup import Startup
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli = CLI()
|
||||
cli.use_startup(Startup)
|
||||
cli.build()
|
||||
cli.run()
|
36
src/cpl_cli/startup.py
Normal file
36
src/cpl_cli/startup.py
Normal file
@ -0,0 +1,36 @@
|
||||
from typing import Optional
|
||||
|
||||
from cpl.application.application_host import ApplicationHost
|
||||
from cpl.application.application_host_abc import ApplicationHostABC
|
||||
from cpl.application.startup_abc import StartupABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
self._app_host: Optional[ApplicationHostABC] = None
|
||||
self._configuration: Optional[ConfigurationABC] = None
|
||||
self._services: Optional[ServiceProviderABC] = None
|
||||
|
||||
def create_application_host(self) -> ApplicationHostABC:
|
||||
self._app_host = ApplicationHost()
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
return self._app_host
|
||||
|
||||
def create_configuration(self) -> ConfigurationABC:
|
||||
self._configuration.add_environment_variables('PYTHON_')
|
||||
self._configuration.add_environment_variables('CPL_')
|
||||
self._configuration.add_console_argument('', 'version', ['v'], '')
|
||||
self._configuration.add_console_argument('-', 'test', ['t'], '')
|
||||
self._configuration.add_console_argument('-', 'var', ['v'], ':')
|
||||
self._configuration.add_console_arguments()
|
||||
|
||||
return self._configuration
|
||||
|
||||
def create_services(self) -> ServiceProviderABC:
|
||||
return self._services
|
Loading…
Reference in New Issue
Block a user