cpl@2022.6.13 - cpl run command #78
							
								
								
									
										53
									
								
								src/cpl_cli/command/run_service.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/cpl_cli/command/run_service.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | |||||||
|  | import os | ||||||
|  | import textwrap | ||||||
|  |  | ||||||
|  | from cpl_cli.command_abc import CommandABC | ||||||
|  | from cpl_core.console.console import Console | ||||||
|  | from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC | ||||||
|  | from cpl_cli.configuration.build_settings import BuildSettings | ||||||
|  | from cpl_cli.configuration.project_settings import ProjectSettings | ||||||
|  | from cpl_cli.live_server.live_server_thread import LiveServerThread | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class RunService(CommandABC): | ||||||
|  |  | ||||||
|  |     def __init__(self, env: ApplicationEnvironmentABC, project_settings: ProjectSettings, build_settings: BuildSettings): | ||||||
|  |         """ | ||||||
|  |         Service for the CLI command start | ||||||
|  |         :param env: | ||||||
|  |         :param project_settings: | ||||||
|  |         :param build_settings: | ||||||
|  |         """ | ||||||
|  |         CommandABC.__init__(self) | ||||||
|  |  | ||||||
|  |         self._env = env | ||||||
|  |         self._project_settings = project_settings | ||||||
|  |         self._build_settings = build_settings | ||||||
|  |  | ||||||
|  |         self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path) | ||||||
|  |  | ||||||
|  |         self._args: list[str] = [] | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def help_message(self) -> str: | ||||||
|  |         return textwrap.dedent("""\ | ||||||
|  |         Starts your application. | ||||||
|  |         Usage: cpl run | ||||||
|  |         """) | ||||||
|  |  | ||||||
|  |     def execute(self, args: list[str]): | ||||||
|  |         """ | ||||||
|  |         Entry point of command | ||||||
|  |         :param args: | ||||||
|  |         :return: | ||||||
|  |         """ | ||||||
|  |         ls_thread = LiveServerThread( | ||||||
|  |             self._project_settings.python_executable, | ||||||
|  |             self._src_dir, | ||||||
|  |             self._args, | ||||||
|  |             self._env, | ||||||
|  |             self._build_settings | ||||||
|  |         ) | ||||||
|  |         ls_thread.start() | ||||||
|  |         ls_thread.join() | ||||||
|  |         Console.write_line() | ||||||
| @@ -4,7 +4,7 @@ | |||||||
|     "Version": { |     "Version": { | ||||||
|       "Major": "2022", |       "Major": "2022", | ||||||
|       "Minor": "6", |       "Minor": "6", | ||||||
|       "Micro": "1.dev4" |       "Micro": "13" | ||||||
|     }, |     }, | ||||||
|     "Author": "Sven Heidemann", |     "Author": "Sven Heidemann", | ||||||
|     "AuthorEmail": "sven.heidemann@sh-edraft.de", |     "AuthorEmail": "sven.heidemann@sh-edraft.de", | ||||||
| @@ -16,7 +16,7 @@ | |||||||
|     "LicenseName": "MIT", |     "LicenseName": "MIT", | ||||||
|     "LicenseDescription": "MIT, see LICENSE for more details.", |     "LicenseDescription": "MIT, see LICENSE for more details.", | ||||||
|     "Dependencies": [ |     "Dependencies": [ | ||||||
|       "cpl-core>=2022.6.1.dev4" |       "cpl-core>=2022.6.13" | ||||||
|     ], |     ], | ||||||
|     "PythonVersion": ">=3.10", |     "PythonVersion": ">=3.10", | ||||||
|     "PythonPath": {}, |     "PythonPath": {}, | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ from cpl_cli.command.install_service import InstallService | |||||||
| from cpl_cli.command.new_service import NewService | from cpl_cli.command.new_service import NewService | ||||||
| from cpl_cli.command.publish_service import PublishService | from cpl_cli.command.publish_service import PublishService | ||||||
| from cpl_cli.command.remove_service import RemoveService | from cpl_cli.command.remove_service import RemoveService | ||||||
|  | from cpl_cli.command.run_service import RunService | ||||||
| from cpl_cli.command.start_service import StartService | from cpl_cli.command.start_service import StartService | ||||||
| from cpl_cli.command.uninstall_service import UninstallService | from cpl_cli.command.uninstall_service import UninstallService | ||||||
| from cpl_cli.command.update_service import UpdateService | from cpl_cli.command.update_service import UpdateService | ||||||
| @@ -84,6 +85,7 @@ class StartupArgumentExtension(StartupExtensionABC): | |||||||
|         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator]) |         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator]) | ||||||
|         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \ |         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \ | ||||||
|             .add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) |             .add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) | ||||||
|  |         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator]) | ||||||
|         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) |         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) | ||||||
|         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, True, validators=[ProjectValidator]) \ |         config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, True, validators=[ProjectValidator]) \ | ||||||
|             .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \ |             .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \ | ||||||
| @@ -110,6 +112,7 @@ class StartupArgumentExtension(StartupExtensionABC): | |||||||
|         services.add_transient(NewService) |         services.add_transient(NewService) | ||||||
|         services.add_transient(PublishService) |         services.add_transient(PublishService) | ||||||
|         services.add_transient(RemoveService) |         services.add_transient(RemoveService) | ||||||
|  |         services.add_transient(RunService) | ||||||
|         services.add_transient(StartService) |         services.add_transient(StartService) | ||||||
|         services.add_transient(UninstallService) |         services.add_transient(UninstallService) | ||||||
|         services.add_transient(UpdateService) |         services.add_transient(UpdateService) | ||||||
|   | |||||||
| @@ -339,7 +339,7 @@ class Configuration(ConfigurationABC): | |||||||
|                 prevent = exe.prevent_next_executable |                 prevent = exe.prevent_next_executable | ||||||
|                 success = True |                 success = True | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             Console.error('An error occurred while executing arguments.', traceback.format_exc()) |             Console.error('An error occurred while executing arguments.') | ||||||
|             sys.exit() |             sys.exit() | ||||||
|  |  | ||||||
|         return success |         return success | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|     "Version": { |     "Version": { | ||||||
|       "Major": "2022", |       "Major": "2022", | ||||||
|       "Minor": "6", |       "Minor": "6", | ||||||
|       "Micro": "1.dev4" |       "Micro": "13" | ||||||
|     }, |     }, | ||||||
|     "Author": "Sven Heidemann", |     "Author": "Sven Heidemann", | ||||||
|     "AuthorEmail": "sven.heidemann@sh-edraft.de", |     "AuthorEmail": "sven.heidemann@sh-edraft.de", | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|     "Version": { |     "Version": { | ||||||
|       "Major": "2022", |       "Major": "2022", | ||||||
|       "Minor": "6", |       "Minor": "6", | ||||||
|       "Micro": "1.dev4" |       "Micro": "13" | ||||||
|     }, |     }, | ||||||
|     "Author": "Sven Heidemann", |     "Author": "Sven Heidemann", | ||||||
|     "AuthorEmail": "sven.heidemann@sh-edraft.de", |     "AuthorEmail": "sven.heidemann@sh-edraft.de", | ||||||
| @@ -16,7 +16,7 @@ | |||||||
|     "LicenseName": "MIT", |     "LicenseName": "MIT", | ||||||
|     "LicenseDescription": "MIT, see LICENSE for more details.", |     "LicenseDescription": "MIT, see LICENSE for more details.", | ||||||
|     "Dependencies": [ |     "Dependencies": [ | ||||||
|       "cpl-core>=2022.6.1.dev4" |       "cpl-core>=2022.6.13" | ||||||
|     ], |     ], | ||||||
|     "PythonVersion": ">=3.10", |     "PythonVersion": ">=3.10", | ||||||
|     "PythonPath": {}, |     "PythonPath": {}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user