From d694c408c07277553200a0fdf72bbfeb3e2fa3b2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 22 May 2022 18:48:33 +0200 Subject: [PATCH] Added CLI logic to generate pipes --- .../_templates/generate/pipe_template.py | 40 +++++++++++++++++++ src/cpl_cli/command/generate_service.py | 7 ++++ src/cpl_cli/startup_argument_extension.py | 1 + src/cpl_core/{pipes => pipe}/__init__.py | 2 +- .../first_char_to_lower_pipe.py | 2 +- src/cpl_core/{pipes => pipe}/pipe_abc.py | 0 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/cpl_cli/_templates/generate/pipe_template.py rename src/cpl_core/{pipes => pipe}/__init__.py (95%) rename src/cpl_core/{pipes => pipe}/first_char_to_lower_pipe.py (78%) rename src/cpl_core/{pipes => pipe}/pipe_abc.py (100%) diff --git a/src/cpl_cli/_templates/generate/pipe_template.py b/src/cpl_cli/_templates/generate/pipe_template.py new file mode 100644 index 00000000..129e13ba --- /dev/null +++ b/src/cpl_cli/_templates/generate/pipe_template.py @@ -0,0 +1,40 @@ +import textwrap +from string import Template + +from cpl_core.utils.string import String +from cpl_cli._templates.template_file_abc import TemplateFileABC + + +class PipeTemplate(TemplateFileABC): + + def __init__(self, name: str, schematic: str, schematic_upper: str, path: str): + TemplateFileABC.__init__(self) + + self._name = f'{String.convert_to_snake_case(name)}_{schematic}.py' + self._class_name = f'{String.first_to_upper(name)}{schematic_upper}' + self._path = path + self._value = textwrap.dedent("""\ + from cpl_core.pipe import PipeABC + + + class $Name(PipeABC): + + def __init__(self): pass + + def transform(self, value: any, *args): + return value + """) + + @property + def name(self) -> str: + return self._name + + @property + def path(self) -> str: + return self._path + + @property + def value(self) -> str: + return Template(self._value).substitute( + Name=self._class_name + ) diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 846e6cee..e546218e 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -2,6 +2,7 @@ import os import sys import textwrap +from cpl_cli._templates.generate.pipe_template import PipeTemplate from cpl_cli._templates.generate.validator_template import ValidatorTemplate from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.console.foreground_color_enum import ForegroundColorEnum @@ -40,6 +41,10 @@ class GenerateService(CommandABC): "Upper": "Enum", "Template": EnumTemplate }, + "pipe": { + "Upper": "Pipe", + "Template": PipeTemplate + }, "service": { "Upper": "Service", "Template": ServiceTemplate @@ -75,6 +80,7 @@ class GenerateService(CommandABC): abc class enum + pipe service settings thread @@ -94,6 +100,7 @@ class GenerateService(CommandABC): 'abc (a|A)', 'class (c|C)', 'enum (e|E)', + 'pipe (p|P)', 'service (s|S)', 'settings (st|ST)', 'thread (t|T)', diff --git a/src/cpl_cli/startup_argument_extension.py b/src/cpl_cli/startup_argument_extension.py index 026e572a..ab7beb4e 100644 --- a/src/cpl_cli/startup_argument_extension.py +++ b/src/cpl_cli/startup_argument_extension.py @@ -66,6 +66,7 @@ class StartupArgumentExtension(StartupExtensionABC): .add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \ + .add_console_argument(ArgumentTypeEnum.Variable, '', 'pipe', ['p', 'P'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \ diff --git a/src/cpl_core/pipes/__init__.py b/src/cpl_core/pipe/__init__.py similarity index 95% rename from src/cpl_core/pipes/__init__.py rename to src/cpl_core/pipe/__init__.py index bf54bda3..b99969fa 100644 --- a/src/cpl_core/pipes/__init__.py +++ b/src/cpl_core/pipe/__init__.py @@ -11,7 +11,7 @@ sh-edraft Common Python library """ -__title__ = 'cpl_core.pipes' +__title__ = 'cpl_core.pipe' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' diff --git a/src/cpl_core/pipes/first_char_to_lower_pipe.py b/src/cpl_core/pipe/first_char_to_lower_pipe.py similarity index 78% rename from src/cpl_core/pipes/first_char_to_lower_pipe.py rename to src/cpl_core/pipe/first_char_to_lower_pipe.py index 0daa6120..a9ad59fd 100644 --- a/src/cpl_core/pipes/first_char_to_lower_pipe.py +++ b/src/cpl_core/pipe/first_char_to_lower_pipe.py @@ -1,4 +1,4 @@ -from cpl_core.pipes.pipe_abc import PipeABC +from cpl_core.pipe.pipe_abc import PipeABC class FirstCharToLowerPipe(PipeABC): diff --git a/src/cpl_core/pipes/pipe_abc.py b/src/cpl_core/pipe/pipe_abc.py similarity index 100% rename from src/cpl_core/pipes/pipe_abc.py rename to src/cpl_core/pipe/pipe_abc.py