Added logic to cpl cli to change cwd only when wanted

This commit is contained in:
Sven Heidemann 2021-04-11 11:12:39 +02:00
parent d51659db3e
commit 284ebe1b11
4 changed files with 26 additions and 17 deletions

View File

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

View File

@ -102,7 +102,9 @@ class GenerateService(CommandABC):
rel_path = '/'.join(parts[:-1]) rel_path = '/'.join(parts[:-1])
class_name = parts[len(parts) - 1] class_name = parts[len(parts) - 1]
if 'src' not in name: Console.write_line(rel_path)
if 'src' not in rel_path:
rel_path = f'src/{rel_path}' rel_path = f'src/{rel_path}'
template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path) template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)

View File

@ -94,6 +94,7 @@ class CommandHandler(ABC):
project_json = os.path.join(self._env.working_directory, project_json) project_json = os.path.join(self._env.working_directory, project_json)
if command.change_cwd:
self._env.set_working_directory( self._env.set_working_directory(
os.path.join(self._env.working_directory, os.path.dirname(project_json)) os.path.join(self._env.working_directory, os.path.dirname(project_json))
) )

View File

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