Added comments
This commit is contained in:
@@ -6,10 +6,19 @@ from cpl_cli.publish.publisher_abc import PublisherABC
|
||||
class BuildService(CommandABC):
|
||||
|
||||
def __init__(self, publisher: PublisherABC):
|
||||
"""
|
||||
Service for the CLI command build
|
||||
:param publisher:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._publisher = publisher
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._publisher.build()
|
||||
Console.write('\n')
|
||||
|
@@ -19,6 +19,11 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
class GenerateService(CommandABC):
|
||||
|
||||
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC):
|
||||
"""
|
||||
Service for the CLI command generate
|
||||
:param configuration:
|
||||
:param runtime:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._schematics = {
|
||||
@@ -53,6 +58,11 @@ class GenerateService(CommandABC):
|
||||
|
||||
@staticmethod
|
||||
def _help(message: str):
|
||||
"""
|
||||
Internal help output
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
Console.error(message)
|
||||
|
||||
schematics = [
|
||||
@@ -68,11 +78,24 @@ class GenerateService(CommandABC):
|
||||
|
||||
@staticmethod
|
||||
def _create_file(file_path: str, value: str):
|
||||
"""
|
||||
Creates the given file with content
|
||||
:param file_path:
|
||||
:param value:
|
||||
:return:
|
||||
"""
|
||||
with open(file_path, 'w') as template:
|
||||
template.write(value)
|
||||
template.close()
|
||||
|
||||
def _generate(self, schematic: str, name: str, template: Callable[TemplateFileABC]):
|
||||
"""
|
||||
Generates files by given schematic, name and template
|
||||
:param schematic:
|
||||
:param name:
|
||||
:param template:
|
||||
:return:
|
||||
"""
|
||||
class_name = name
|
||||
rel_path = ''
|
||||
if '/' in name:
|
||||
@@ -104,6 +127,11 @@ class GenerateService(CommandABC):
|
||||
)
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if len(args) == 0:
|
||||
self._help('Usage: cpl generate <schematic> [options]')
|
||||
exit()
|
||||
|
@@ -6,9 +6,17 @@ from cpl_cli.command_abc import CommandABC
|
||||
class HelpService(CommandABC):
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Service for CLI command help
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
Console.write_line('Available Commands:')
|
||||
commands = [
|
||||
['build (b|B)', 'Prepares files for publish into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.'],
|
||||
|
@@ -19,12 +19,21 @@ from cpl_cli.error import Error
|
||||
class InstallService(CommandABC):
|
||||
|
||||
def __init__(self, runtime: ApplicationRuntimeABC, configuration: ConfigurationABC):
|
||||
"""
|
||||
Service for the CLI command install
|
||||
:param runtime:
|
||||
:param configuration:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._runtime = runtime
|
||||
self._config = configuration
|
||||
|
||||
def _install_project(self):
|
||||
"""
|
||||
Installs dependencies of CPl project
|
||||
:return:
|
||||
"""
|
||||
project: ProjectSettings = self._config.get_configuration(ProjectSettings)
|
||||
build: BuildSettings = self._config.get_configuration(BuildSettings)
|
||||
|
||||
@@ -88,6 +97,11 @@ class InstallService(CommandABC):
|
||||
}
|
||||
|
||||
def _install_package(self, package: str):
|
||||
"""
|
||||
Installs given package
|
||||
:param package:
|
||||
:return:
|
||||
"""
|
||||
is_already_in_project = False
|
||||
project: ProjectSettings = self._config.get_configuration(ProjectSettings)
|
||||
build: BuildSettings = self._config.get_configuration(BuildSettings)
|
||||
@@ -165,6 +179,11 @@ class InstallService(CommandABC):
|
||||
Pip.reset_executable()
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if len(args) == 0:
|
||||
self._install_project()
|
||||
else:
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from packaging import version
|
||||
@@ -30,6 +29,11 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
class NewService(CommandABC):
|
||||
|
||||
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC):
|
||||
"""
|
||||
Service for the CLI command new
|
||||
:param configuration:
|
||||
:param runtime:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._config = configuration
|
||||
@@ -90,12 +94,20 @@ class NewService(CommandABC):
|
||||
self._build.from_dict(self._build_dict)
|
||||
|
||||
def _create_project_json(self):
|
||||
"""
|
||||
Creates cpl.json content
|
||||
:return:
|
||||
"""
|
||||
self._project_json = {
|
||||
ProjectSettings.__name__: self._project_dict,
|
||||
BuildSettings.__name__: self._build_dict
|
||||
}
|
||||
|
||||
def _get_project_path(self) -> Optional[str]:
|
||||
"""
|
||||
Gets project path
|
||||
:return:
|
||||
"""
|
||||
project_path = os.path.join(self._runtime.working_directory, self._project.name)
|
||||
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
||||
Console.error('Project path is not empty\n')
|
||||
@@ -104,6 +116,10 @@ class NewService(CommandABC):
|
||||
return project_path
|
||||
|
||||
def _get_project_informations(self):
|
||||
"""
|
||||
Gets project informations from user
|
||||
:return:
|
||||
"""
|
||||
result = Console.read('Do you want to use application host? (y/n) ')
|
||||
if result.lower() == 'y':
|
||||
self._use_application_api = True
|
||||
@@ -121,6 +137,11 @@ class NewService(CommandABC):
|
||||
# self._use_service_providing = True
|
||||
|
||||
def _build_project_dir(self, project_path: str):
|
||||
"""
|
||||
Builds the project files
|
||||
:param project_path:
|
||||
:return:
|
||||
"""
|
||||
if not os.path.isdir(project_path):
|
||||
os.makedirs(project_path)
|
||||
|
||||
@@ -155,6 +176,12 @@ class NewService(CommandABC):
|
||||
|
||||
@staticmethod
|
||||
def _create_template(project_path: str, template: TemplateFileABC):
|
||||
"""
|
||||
Creates template
|
||||
:param project_path:
|
||||
:param template:
|
||||
:return:
|
||||
"""
|
||||
file_path = os.path.join(project_path, template.path, template.name)
|
||||
file_rel_path = os.path.join(project_path, template.path)
|
||||
|
||||
@@ -166,6 +193,11 @@ class NewService(CommandABC):
|
||||
license_file.close()
|
||||
|
||||
def _console(self, args: list[str]):
|
||||
"""
|
||||
Generates new console project
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
name = self._config.get_configuration(self._command)
|
||||
|
||||
self._create_project_settings(name)
|
||||
@@ -182,6 +214,11 @@ class NewService(CommandABC):
|
||||
Console.error('Could not create project', str(e))
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._command = args[0]
|
||||
if self._command == 'console':
|
||||
self._console(args)
|
||||
|
@@ -6,10 +6,19 @@ from cpl_cli.publish.publisher_abc import PublisherABC
|
||||
class PublishService(CommandABC):
|
||||
|
||||
def __init__(self, publisher: PublisherABC):
|
||||
"""
|
||||
Service for the CLI command publish
|
||||
:param publisher:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._publisher = publisher
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._publisher.publish()
|
||||
Console.write('\n')
|
||||
|
@@ -5,9 +5,18 @@ from cpl_cli.live_server.live_server_service import LiveServerService
|
||||
class StartService(CommandABC):
|
||||
|
||||
def __init__(self, live_server: LiveServerService):
|
||||
"""
|
||||
Service for the CLI command start
|
||||
:param live_server:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._live_server = live_server
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._live_server.start()
|
||||
|
@@ -16,6 +16,12 @@ class UninstallService(CommandABC):
|
||||
|
||||
def __init__(self, runtime: ApplicationRuntimeABC, build_settings: BuildSettings,
|
||||
project_settings: ProjectSettings):
|
||||
"""
|
||||
Service for the CLI command uninstall
|
||||
:param runtime:
|
||||
:param build_settings:
|
||||
:param project_settings:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._runtime = runtime
|
||||
@@ -59,6 +65,11 @@ class UninstallService(CommandABC):
|
||||
}
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if len(args) == 0:
|
||||
Console.error(f'Expected package')
|
||||
Console.error(f'Usage: cpl uninstall <package>')
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from cpl.application import ApplicationRuntimeABC
|
||||
from cpl.console import ForegroundColorEnum
|
||||
@@ -14,30 +13,35 @@ from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
class UpdateService(CommandABC):
|
||||
|
||||
def __init__(self, runtime: ApplicationRuntimeABC, project_settings: ProjectSettings):
|
||||
"""
|
||||
Service for the CLI command update
|
||||
:param runtime:
|
||||
:param project_settings:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._runtime = runtime
|
||||
self._project_settings = project_settings
|
||||
|
||||
@staticmethod
|
||||
def _install_package(name: str):
|
||||
Pip.install(
|
||||
name,
|
||||
'--upgrade',
|
||||
'--upgrade-strategy',
|
||||
'eager',
|
||||
source='https://pip.sh-edraft.de' if 'sh_cpl' in name else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
def _update_project_dependencies(self):
|
||||
"""
|
||||
Updates project dependencies
|
||||
:return:
|
||||
"""
|
||||
for package in self._project_settings.dependencies:
|
||||
name = package
|
||||
if '==' in package:
|
||||
name = package.split('==')[0]
|
||||
|
||||
self._install_package(name)
|
||||
Pip.install(
|
||||
name,
|
||||
'--upgrade',
|
||||
'--upgrade-strategy',
|
||||
'eager',
|
||||
source='https://pip.sh-edraft.de' if 'sh_cpl' in name else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
new_package = Pip.get_package(name)
|
||||
if new_package is None:
|
||||
@@ -47,6 +51,10 @@ class UpdateService(CommandABC):
|
||||
self._project_json_update_dependency(package, new_package)
|
||||
|
||||
def _check_project_dependencies(self):
|
||||
"""
|
||||
Checks project dependencies for updates
|
||||
:return:
|
||||
"""
|
||||
Console.spinner(
|
||||
'Collecting installed dependencies', self._update_project_dependencies,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -56,6 +64,10 @@ class UpdateService(CommandABC):
|
||||
|
||||
@staticmethod
|
||||
def _check_outdated():
|
||||
"""
|
||||
Checks for outdated packages in project
|
||||
:return:
|
||||
"""
|
||||
table_str: bytes = Console.spinner(
|
||||
'Analyzing for available package updates', Pip.get_outdated,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -73,6 +85,12 @@ class UpdateService(CommandABC):
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
def _project_json_update_dependency(self, old_package: str, new_package: str):
|
||||
"""
|
||||
Writes new package version to cpl.json
|
||||
:param old_package:
|
||||
:param new_package:
|
||||
:return:
|
||||
"""
|
||||
content = ''
|
||||
with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'r') as project:
|
||||
content = project.read()
|
||||
@@ -89,6 +107,11 @@ class UpdateService(CommandABC):
|
||||
project.close()
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
Pip.set_executable(self._project_settings.python_path)
|
||||
self._check_project_dependencies()
|
||||
self._check_outdated()
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
import platform
|
||||
@@ -14,9 +13,17 @@ from cpl_cli.command_abc import CommandABC
|
||||
class VersionService(CommandABC):
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Service for the CLI command version
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
Console.set_foreground_color(ForegroundColorEnum.yellow)
|
||||
Console.banner('CPL CLI')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
Reference in New Issue
Block a user