Improved version command

This commit is contained in:
Sven Heidemann 2021-10-03 11:23:17 +02:00
parent f8ebb4f1d7
commit a8011267d9
2 changed files with 52 additions and 52 deletions

View File

@ -45,9 +45,14 @@ class VersionService(CommandABC):
Console.write_line(f'OS: {platform.system()} {platform.processor()}')
Console.write_line('\nCPL packages:')
cpl_packages = [
'cpl_core',
'cpl_cli',
'cpl_query'
]
packages = []
for importer, modname, is_pkg in pkgutil.iter_modules(cpl_core.__path__):
module = importer.find_module(modname).load_module(modname)
for modname in cpl_packages:
module = pkgutil.find_loader(modname).load_module(modname)
if '__version__' in dir(module):
packages.append([f'{modname}', module.__version__])

View File

@ -25,30 +25,25 @@ from cpl_cli.error import Error
from cpl_cli.live_server.live_server_service import LiveServerService
from cpl_cli.publish.publisher_service import PublisherService
from cpl_cli.publish.publisher_abc import PublisherABC
from cpl_core.environment import ApplicationEnvironment
class Startup(StartupABC):
def __init__(self, config: ConfigurationABC, services: ServiceCollectionABC):
def __init__(self):
StartupABC.__init__(self)
self._configuration = config
self._env = self._configuration.environment
self._services = services
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
environment.set_runtime_directory(os.path.dirname(__file__))
configuration.argument_error_function = Error.error
self._env.set_runtime_directory(os.path.dirname(__file__))
configuration.add_environment_variables('PYTHON_')
configuration.add_environment_variables('CPL_')
configuration.add_json_file('appsettings.json', path=environment.runtime_directory, optional=False, output=False)
def configure_configuration(self) -> ConfigurationABC:
self._configuration.argument_error_function = Error.error
self._configuration.add_environment_variables('PYTHON_')
self._configuration.add_environment_variables('CPL_')
self._configuration.add_json_file('appsettings.json', path=self._env.runtime_directory,
optional=False, output=False)
self._configuration.add_console_argument(ConsoleArgument('', 'add', ['a', 'a'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'generate', ['g', 'G'], '', console_arguments=[
configuration.add_console_argument(ConsoleArgument('', 'add', ['a', 'a'], ' '))
configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], ''))
configuration.add_console_argument(ConsoleArgument('', 'generate', ['g', 'G'], '', console_arguments=[
ConsoleArgument('', 'abc', ['a', 'A'], ' '),
ConsoleArgument('', 'class', ['c', 'C'], ' '),
ConsoleArgument('', 'enum', ['e', 'E'], ' '),
@ -56,54 +51,54 @@ class Startup(StartupABC):
ConsoleArgument('', 'settings', ['st', 'ST'], ' '),
ConsoleArgument('', 'thread', ['t', 't'], ' ')
]))
self._configuration.add_console_argument(
configuration.add_console_argument(
ConsoleArgument('', 'help', ['h', 'H'], ' ', is_value_token_optional=True)
)
self._configuration.add_console_argument(
configuration.add_console_argument(
ConsoleArgument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True)
)
self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', console_arguments=[
configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', console_arguments=[
ConsoleArgument('', 'console', ['c', 'C'], ' '),
ConsoleArgument('', 'library', ['l', 'L'], ' ')
]))
self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'remove', ['r', 'R'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'start', ['s', 'S'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
configuration.add_console_argument(ConsoleArgument('', 'remove', ['r', 'R'], ' '))
configuration.add_console_argument(ConsoleArgument('', 'start', ['s', 'S'], ''))
configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
self._configuration.add_console_argument(ConsoleArgument('', '--help', ['-h', '-H'], ''))
configuration.add_console_argument(ConsoleArgument('', '--help', ['-h', '-H'], ''))
if os.path.isfile(os.path.join(self._env.working_directory, 'cpl-workspace.json')):
self._configuration.add_json_file('cpl-workspace.json', optional=True, output=False)
workspace: Optional[WorkspaceSettings] = self._configuration.get_configuration(WorkspaceSettings)
if os.path.isfile(os.path.join(environment.working_directory, 'cpl-workspace.json')):
configuration.add_json_file('cpl-workspace.json', optional=True, output=False)
workspace: Optional[WorkspaceSettings] = configuration.get_configuration(WorkspaceSettings)
for script in workspace.scripts:
self._configuration.add_console_argument(
configuration.add_console_argument(
ConsoleArgument('', script, [], ' ', is_value_token_optional=True))
self._configuration.add_console_arguments(error=False)
configuration.add_console_arguments(error=False)
return self._configuration
return configuration
def configure_services(self) -> ServiceProviderABC:
self._services.add_singleton(CommandHandler)
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
services.add_singleton(CommandHandler)
self._services.add_transient(PublisherABC, PublisherService)
self._services.add_transient(LiveServerService)
services.add_transient(PublisherABC, PublisherService)
services.add_transient(LiveServerService)
self._services.add_transient(AddService)
self._services.add_transient(BuildService)
self._services.add_transient(CustomScriptService)
self._services.add_transient(GenerateService)
self._services.add_transient(HelpService)
self._services.add_transient(InstallService)
self._services.add_transient(NewService)
self._services.add_transient(PublishService)
self._services.add_transient(RemoveService)
self._services.add_transient(StartService)
self._services.add_transient(UninstallService)
self._services.add_transient(UpdateService)
self._services.add_transient(VersionService)
services.add_transient(AddService)
services.add_transient(BuildService)
services.add_transient(CustomScriptService)
services.add_transient(GenerateService)
services.add_transient(HelpService)
services.add_transient(InstallService)
services.add_transient(NewService)
services.add_transient(PublishService)
services.add_transient(RemoveService)
services.add_transient(StartService)
services.add_transient(UninstallService)
services.add_transient(UpdateService)
services.add_transient(VersionService)
return self._services.build_service_provider()
return services.build_service_provider()