cpl@2022.6.3 - Verbesserung der Parameter #67

Merged
edraft merged 25 commits from 2022.6.3 into 2022.6 2022-05-22 17:38:22 +02:00
5 changed files with 37 additions and 52 deletions
Showing only changes of commit 94c82e6701 - Show all commits

View File

@ -1,5 +1,5 @@
import sys
import textwrap
from typing import Optional
from cpl_core.console.console import Console
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
@ -21,10 +21,7 @@ class HelpService(CommandABC):
def help_message(self) -> str:
return textwrap.dedent("""\
Lists available command and their short descriptions.
Usage: cpl help <command>
Arguments:
command The command to display the help message for
Usage: cpl help
""")
def run(self, args: list[str]):
@ -33,20 +30,9 @@ 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:
Console.error(f'Unexpected argument(s): {", ".join(args)}')
sys.exit()
Console.write_line('Available Commands:')
commands = [
@ -68,3 +54,4 @@ class HelpService(CommandABC):
Console.write(f'\n\t{name} ')
Console.set_foreground_color(ForegroundColorEnum.default)
Console.write(f'{description}')
Console.write_line('\nRun \'cpl <command> --help\' for command specific information\'s')

View File

@ -1,6 +1,7 @@
from abc import abstractmethod, ABC
from cpl_core.configuration.executable_argument import ExecutableArgument
from cpl_core.console import Console
class CommandABC(ExecutableArgument):
@ -12,3 +13,14 @@ class CommandABC(ExecutableArgument):
@property
@abstractmethod
def help_message(self) -> str: pass
def execute(self, args: list[str]):
Console.write_line(args)
if 'help' in args:
Console.write_line(self.help_message)
return
self.run(args)
@abstractmethod
def run(self, args: list[str]): pass

View File

@ -1,18 +1,5 @@
import os
from cpl_cli.command.add_service import AddService
from cpl_cli.command.build_service import BuildService
from cpl_cli.command.custom_script_service import CustomScriptService
from cpl_cli.command.generate_service import GenerateService
from cpl_cli.command.help_service import HelpService
from cpl_cli.command.install_service import InstallService
from cpl_cli.command.new_service import NewService
from cpl_cli.command.publish_service import PublishService
from cpl_cli.command.remove_service import RemoveService
from cpl_cli.command.start_service import StartService
from cpl_cli.command.uninstall_service import UninstallService
from cpl_cli.command.update_service import UpdateService
from cpl_cli.command.version_service import VersionService
from cpl_cli.error import Error
from cpl_cli.live_server.live_server_service import LiveServerService
from cpl_cli.publish.publisher_abc import PublisherABC
@ -43,18 +30,4 @@ class Startup(StartupABC):
services.add_transient(PublisherABC, PublisherService)
services.add_transient(LiveServerService)
services.add_transient(AddService)
services.add_transient(BuildService)
services.add_transient(CustomScriptService)
services.add_transient(GenerateService)
services.add_transient(HelpService)
services.add_transient(InstallService)
services.add_transient(NewService)
services.add_transient(PublishService)
services.add_transient(RemoveService)
services.add_transient(StartService)
services.add_transient(UninstallService)
services.add_transient(UpdateService)
services.add_transient(VersionService)
return services.build_service_provider()

View File

@ -1,6 +1,7 @@
import os
from typing import Optional
from cpl_cli import CommandABC
from cpl_cli.command.add_service import AddService
from cpl_cli.command.build_service import BuildService
from cpl_cli.command.custom_script_service import CustomScriptService
@ -87,11 +88,23 @@ class StartupArgumentExtension(StartupExtensionABC):
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'version', ['v', 'V'], VersionService)
config.for_each_argument(
lambda a: a.add_console_argument(ArgumentTypeEnum.Executable, '--', 'help', ['h', 'H'], HelpService)
lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, '--', 'help', ['h', 'H'])
)
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'help', ['h', 'H'], HelpService)
self._read_cpl_environment(config, env)
def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC):
pass
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
services.add_transient(CommandABC, AddService)
services.add_transient(CommandABC, BuildService)
services.add_transient(CommandABC, CustomScriptService)
services.add_transient(CommandABC, GenerateService)
services.add_transient(CommandABC, HelpService)
services.add_transient(CommandABC, InstallService)
services.add_transient(CommandABC, NewService)
services.add_transient(CommandABC, PublishService)
services.add_transient(CommandABC, RemoveService)
services.add_transient(CommandABC, StartService)
services.add_transient(CommandABC, UninstallService)
services.add_transient(CommandABC, UpdateService)
services.add_transient(CommandABC, VersionService)

View File

@ -4,6 +4,7 @@ import sys
from collections.abc import Callable
from typing import Union, Type, Optional
from cpl_cli.command_abc import CommandABC
from cpl_core.configuration.argument_abc import ArgumentABC
from cpl_core.configuration.argument_builder import ArgumentBuilder
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
@ -281,6 +282,5 @@ class Configuration(ConfigurationABC):
self._parse_arguments(executables, arg_list, self._argument_types)
for exe in executables:
service: ExecutableArgument = services.get_service(exe.executable_type)
service.run(self._additional_arguments)
cmd: CommandABC = services.get_service(exe.executable_type)
cmd.execute(self._additional_arguments)