Added CLI logic to generate pipes

This commit is contained in:
Sven Heidemann 2022-05-22 18:48:33 +02:00
parent d1bb266d49
commit d694c408c0
6 changed files with 50 additions and 2 deletions

View File

@ -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
)

View File

@ -2,6 +2,7 @@ import os
import sys import sys
import textwrap import textwrap
from cpl_cli._templates.generate.pipe_template import PipeTemplate
from cpl_cli._templates.generate.validator_template import ValidatorTemplate from cpl_cli._templates.generate.validator_template import ValidatorTemplate
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.console.foreground_color_enum import ForegroundColorEnum
@ -40,6 +41,10 @@ class GenerateService(CommandABC):
"Upper": "Enum", "Upper": "Enum",
"Template": EnumTemplate "Template": EnumTemplate
}, },
"pipe": {
"Upper": "Pipe",
"Template": PipeTemplate
},
"service": { "service": {
"Upper": "Service", "Upper": "Service",
"Template": ServiceTemplate "Template": ServiceTemplate
@ -75,6 +80,7 @@ class GenerateService(CommandABC):
abc abc
class class
enum enum
pipe
service service
settings settings
thread thread
@ -94,6 +100,7 @@ class GenerateService(CommandABC):
'abc (a|A)', 'abc (a|A)',
'class (c|C)', 'class (c|C)',
'enum (e|E)', 'enum (e|E)',
'pipe (p|P)',
'service (s|S)', 'service (s|S)',
'settings (st|ST)', 'settings (st|ST)',
'thread (t|T)', 'thread (t|T)',

View File

@ -66,6 +66,7 @@ class StartupArgumentExtension(StartupExtensionABC):
.add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \ .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, '', 'service', ['s', 'S'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \

View File

@ -11,7 +11,7 @@ sh-edraft Common Python library
""" """
__title__ = 'cpl_core.pipes' __title__ = 'cpl_core.pipe'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'

View File

@ -1,4 +1,4 @@
from cpl_core.pipes.pipe_abc import PipeABC from cpl_core.pipe.pipe_abc import PipeABC
class FirstCharToLowerPipe(PipeABC): class FirstCharToLowerPipe(PipeABC):