sh_cpl/src/cpl_cli/cli.py

48 lines
1.4 KiB
Python
Raw Normal View History

2022-01-19 12:44:23 +01:00
import sys
2022-05-19 18:09:25 +02:00
import traceback
2021-03-03 19:37:35 +01:00
from cpl_cli.error import Error
2021-08-05 14:21:42 +02:00
from cpl_core.application.application_abc import ApplicationABC
from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console
2022-05-22 20:27:58 +02:00
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
2021-03-03 18:37:54 +01:00
class CLI(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
2021-03-14 16:01:15 +01:00
"""
CPL CLI
"""
ApplicationABC.__init__(self, config, services)
2021-03-03 18:37:54 +01:00
self._options: list[str] = []
2021-03-03 19:37:35 +01:00
2021-03-03 18:37:54 +01:00
def configure(self):
2022-05-19 08:25:32 +02:00
pass
2021-03-03 18:37:54 +01:00
def main(self):
2021-03-14 16:01:15 +01:00
"""
Entry point of the CPL CLI
:return:
"""
2021-03-15 18:25:53 +01:00
try:
result = self._configuration.parse_console_arguments(self._services)
if result:
Console.write_line()
return
if len(self._configuration.additional_arguments) == 0:
Error.error('Expected command')
return
unexpected_arguments = ', '.join(self._configuration.additional_arguments)
Error.error(f'Unexpected argument(s): {unexpected_arguments}')
Console.write_line()
2021-03-15 18:25:53 +01:00
except KeyboardInterrupt:
2021-03-15 18:28:33 +01:00
Console.write_line()
2022-01-19 12:44:23 +01:00
sys.exit()
2022-05-19 18:09:25 +02:00
except Exception as e:
Console.error(str(e), traceback.format_exc())
sys.exit()