2021.4.6 #25

Merged
edraft merged 57 commits from 2021.4.6 into 2021.4.post1 2021-04-11 15:54:38 +02:00
3 changed files with 44 additions and 27 deletions
Showing only changes of commit 1c353bbcdf - Show all commits

View File

@ -33,17 +33,17 @@ class CLI(ApplicationABC):
def configure(self):
self._command_handler: CommandHandler = self._services.get_service(CommandHandler)
self._command_handler.add_command(CommandModel('build', ['h', 'B'], BuildService, True, True))
self._command_handler.add_command(CommandModel('generate', ['g', 'G'], GenerateService, True, False))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], HelpService, False, False))
self._command_handler.add_command(CommandModel('install', ['i', 'I'], InstallService, True, True))
self._command_handler.add_command(CommandModel('new', ['n', 'N'], NewService, False, True))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], PublishService, True, True))
self._command_handler.add_command(CommandModel('remove', ['r', 'R'], RemoveService, True, False))
self._command_handler.add_command(CommandModel('start', ['s', 'S'], StartService, True, True))
self._command_handler.add_command(CommandModel('uninstall', ['ui', 'UI'], UninstallService, True, True))
self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, True, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False, False))
self._command_handler.add_command(CommandModel('build', ['h', 'B'], BuildService, False, True, True))
self._command_handler.add_command(CommandModel('generate', ['g', 'G'], GenerateService, False, True, False))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], HelpService, False, False, False))
self._command_handler.add_command(CommandModel('install', ['i', 'I'], InstallService, False, True, True))
self._command_handler.add_command(CommandModel('new', ['n', 'N'], NewService, False, False, True))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], PublishService, False, True, True))
self._command_handler.add_command(CommandModel('remove', ['r', 'R'], RemoveService, True, True, False))
self._command_handler.add_command(CommandModel('start', ['s', 'S'], StartService, False, True, True))
self._command_handler.add_command(CommandModel('uninstall', ['ui', 'UI'], UninstallService, False, True, True))
self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, False, True, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False, False, False))
def main(self):
"""

View File

@ -5,6 +5,7 @@ from typing import Optional
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl.utils.string import String
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.error import Error
from cpl_cli.command_model import CommandModel
@ -57,14 +58,23 @@ class CommandHandler(ABC):
workspace = self._config.get_configuration(WorkspaceSettings)
if command.is_project_needed:
if os.path.isfile(
os.path.join(
name = os.path.basename(self._env.working_directory)
project_path = os.path.join(
self._env.working_directory,
f'{os.path.basename(self._env.working_directory)}.json'
f'{name}.json'
)
):
project_path_camel_case = os.path.join(
self._env.working_directory,
f'{String.convert_to_camel_case(name)}.json'
)
if os.path.isfile(project_path):
project_name = os.path.basename(self._env.working_directory)
if os.path.isfile(project_path_camel_case):
project_name = String.convert_to_camel_case(name)
if command.is_workspace_needed:
if workspace is None and project_name is None:
Error.error(
'The command requires to be run in an CPL workspace or project, '
@ -75,6 +85,8 @@ class CommandHandler(ABC):
if project_name is None:
project_name = workspace.default_project
Console.write_line(project_name)
self._config.add_configuration('ProjectName', project_name)
project_json = f'{project_name}.json'

View File

@ -5,11 +5,12 @@ from cpl_cli.command_abc import CommandABC
class CommandModel:
def __init__(self, name: str, aliases: list[str], command: Callable[CommandABC], is_project_needed: bool,
change_cwd: bool):
def __init__(self, name: str, aliases: list[str], command: Callable[CommandABC], is_workspace_needed: bool,
is_project_needed: bool, change_cwd: bool):
self._name = name
self._aliases = aliases
self._command = command
self._is_workspace_needed = is_workspace_needed
self._is_project_needed = is_project_needed
self._change_cwd = change_cwd
@ -25,6 +26,10 @@ class CommandModel:
def command(self) -> Callable[CommandABC]:
return self._command
@property
def is_workspace_needed(self) -> bool:
return self._is_workspace_needed
@property
def is_project_needed(self) -> bool:
return self._is_project_needed