2022-05-22 18:32:34 +02:00
|
|
|
from typing import Type
|
|
|
|
|
|
|
|
import pkg_resources
|
|
|
|
|
2021-03-03 18:37:54 +01:00
|
|
|
from cpl_cli.cli import CLI
|
|
|
|
from cpl_cli.startup import Startup
|
2022-05-22 18:32:34 +02:00
|
|
|
from cpl_cli.startup_argument_extension import StartupArgumentExtension
|
|
|
|
from cpl_core.application.application_builder import ApplicationBuilder
|
|
|
|
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
|
|
|
|
|
|
|
|
|
|
|
def get_startup_extensions() -> list[Type[StartupExtensionABC]]:
|
|
|
|
blacklisted_packages = ['cpl-cli']
|
|
|
|
startup_extensions = []
|
|
|
|
|
|
|
|
installed_packages = pkg_resources.working_set
|
|
|
|
for p in installed_packages:
|
|
|
|
package = str(p).split(' ')[0]
|
|
|
|
if not package.startswith('cpl-') or package in blacklisted_packages:
|
|
|
|
continue
|
|
|
|
|
|
|
|
package = package.replace('-', '_')
|
|
|
|
loaded_package = __import__(package)
|
|
|
|
if '__cli_startup_extension__' not in dir(loaded_package):
|
|
|
|
continue
|
|
|
|
startup_extensions.append(loaded_package.__cli_startup_extension__)
|
|
|
|
|
|
|
|
return startup_extensions
|
2021-03-03 18:37:54 +01:00
|
|
|
|
2021-03-08 20:29:08 +01:00
|
|
|
|
|
|
|
def main():
|
2021-03-19 14:15:53 +01:00
|
|
|
app_builder = ApplicationBuilder(CLI)
|
|
|
|
app_builder.use_startup(Startup)
|
2022-05-19 18:09:25 +02:00
|
|
|
app_builder.use_extension(StartupArgumentExtension)
|
2022-05-22 18:32:34 +02:00
|
|
|
for extension in get_startup_extensions():
|
|
|
|
app_builder.use_extension(extension)
|
|
|
|
|
2021-03-19 14:15:53 +01:00
|
|
|
app_builder.build().run()
|
2021-03-09 22:29:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
2022-05-22 18:32:34 +02:00
|
|
|
|
2022-06-03 23:35:07 +02:00
|
|
|
# ((
|
|
|
|
# ( `)
|
|
|
|
# ; / ,
|
|
|
|
# / \/
|
|
|
|
# / |
|
|
|
|
# / ~/
|
|
|
|
# / ) ) ~ edraft
|
|
|
|
# ___// | /
|
|
|
|
# `--' \_~-,
|