Improved argument handling
This commit is contained in:
@@ -23,6 +23,7 @@ class AddService(CommandABC):
|
||||
|
||||
self._config = config
|
||||
self._workspace = workspace
|
||||
self._is_simulation = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -35,8 +36,9 @@ class AddService(CommandABC):
|
||||
target-project: Name of the project to be referenced
|
||||
""")
|
||||
|
||||
@staticmethod
|
||||
def _edit_project_file(source: str, project_settings: ProjectSettings, build_settings: BuildSettings):
|
||||
def _edit_project_file(self, source: str, project_settings: ProjectSettings, build_settings: BuildSettings):
|
||||
if self._is_simulation:
|
||||
return
|
||||
with open(source, 'w') as file:
|
||||
file.write(json.dumps({
|
||||
ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(project_settings),
|
||||
@@ -50,6 +52,11 @@ class AddService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if 'simulate' in args:
|
||||
args.remove('simulate')
|
||||
Console.write_line('Simulating:')
|
||||
self._is_simulation = True
|
||||
|
||||
if len(args) == 0:
|
||||
Console.error('Expected source and target project')
|
||||
return
|
||||
@@ -59,7 +66,7 @@ class AddService(CommandABC):
|
||||
return
|
||||
|
||||
elif len(args) > 2:
|
||||
Console.error(f'Unexpected argument: {" ".join(args[2:])}')
|
||||
Console.error(f'Unexpected argument(s): {", ".join(args[2:])}')
|
||||
return
|
||||
|
||||
# file names
|
||||
|
@@ -4,20 +4,18 @@ from typing import Optional
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl_cli.command_handler_service import CommandHandler
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
|
||||
|
||||
class HelpService(CommandABC):
|
||||
|
||||
def __init__(self, services: ServiceProviderABC, cmd_handler: CommandHandler):
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
"""
|
||||
Service for CLI command help
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._services = services
|
||||
self._commands = cmd_handler.commands
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -35,20 +33,20 @@ class HelpService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if len(args) > 0:
|
||||
command_name = args[0]
|
||||
command: Optional[CommandABC] = None
|
||||
for cmd in self._commands:
|
||||
if cmd.name == command_name or command_name in cmd.aliases:
|
||||
command = self._services.get_service(cmd.command)
|
||||
|
||||
if command is None:
|
||||
Console.error(f'Invalid argument: {command_name}')
|
||||
return
|
||||
|
||||
Console.write_line(command.help_message)
|
||||
|
||||
return
|
||||
# if len(args) > 0:
|
||||
# command_name = args[0]
|
||||
# command: Optional[CommandABC] = None
|
||||
# for cmd in self._commands:
|
||||
# if cmd.name == command_name or command_name in cmd.aliases:
|
||||
# command = self._services.get_service(cmd.command)
|
||||
#
|
||||
# if command is None:
|
||||
# Console.error(f'Invalid argument: {command_name}')
|
||||
# return
|
||||
#
|
||||
# Console.write_line(command.help_message)
|
||||
#
|
||||
# return
|
||||
|
||||
Console.write_line('Available Commands:')
|
||||
commands = [
|
||||
|
@@ -25,6 +25,7 @@ class RemoveService(CommandABC):
|
||||
self._env = env
|
||||
|
||||
self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
|
||||
self._is_simulation = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -36,8 +37,10 @@ class RemoveService(CommandABC):
|
||||
project The name of the project to delete
|
||||
""")
|
||||
|
||||
@staticmethod
|
||||
def _create_file(file_name: str, content: dict):
|
||||
def _create_file(self, file_name: str, content: dict):
|
||||
if self._is_simulation:
|
||||
return
|
||||
|
||||
if not os.path.isabs(file_name):
|
||||
file_name = os.path.abspath(file_name)
|
||||
|
||||
@@ -70,6 +73,11 @@ class RemoveService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if 'simulate' in args:
|
||||
args.remove('simulate')
|
||||
Console.write_line('Simulating:')
|
||||
self._is_simulation = True
|
||||
|
||||
project_name = args[0]
|
||||
if project_name not in self._workspace.projects:
|
||||
Console.error(f'Project {project_name} not found in workspace.')
|
||||
|
Reference in New Issue
Block a user