sh_cpl/src/cpl_cli/main.py

59 lines
1.7 KiB
Python
Raw Normal View History

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
from cpl_cli.startup_argument_extension import StartupArgumentExtension
from cpl_cli.startup_migration_extension import StartupMigrationExtension
2022-06-27 10:52:26 +02:00
from cpl_cli.startup_workspace_extension import StartupWorkspaceExtension
from cpl_core.application.application_builder import ApplicationBuilder
from cpl_core.application.startup_extension_abc import StartupExtensionABC
2022-12-18 12:03:41 +01:00
from cpl_core.console import Console
def get_startup_extensions() -> list[Type[StartupExtensionABC]]:
2023-02-20 15:55:20 +01:00
blacklisted_packages = ["cpl-cli"]
startup_extensions = []
installed_packages = pkg_resources.working_set
for p in installed_packages:
2023-02-20 15:55:20 +01:00
package = str(p).split(" ")[0]
if not package.startswith("cpl-") or package in blacklisted_packages:
continue
2023-02-20 15:55:20 +01:00
package = package.replace("-", "_")
loaded_package = __import__(package)
2023-02-20 15:55:20 +01:00
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-06-27 10:52:26 +02:00
app_builder.use_extension(StartupWorkspaceExtension)
2022-05-19 18:09:25 +02:00
app_builder.use_extension(StartupArgumentExtension)
app_builder.use_extension(StartupMigrationExtension)
for extension in get_startup_extensions():
app_builder.use_extension(extension)
2021-03-19 14:15:53 +01:00
app_builder.build().run()
2022-12-18 12:03:41 +01:00
Console.write_line()
2021-03-09 22:29:14 +01:00
2023-02-20 15:55:20 +01:00
if __name__ == "__main__":
2021-03-09 22:29:14 +01:00
main()
2022-06-03 23:35:07 +02:00
# ((
# ( `)
# ; / ,
# / \/
# / |
# / ~/
# / ) ) ~ edraft
# ___// | /
# `--' \_~-,