Improved new command to use workspace when found

This commit is contained in:
2021-04-09 22:09:55 +02:00
parent d19c47e571
commit 7ad01d4bdd
8 changed files with 105 additions and 59 deletions

View File

@@ -1,3 +1,4 @@
import os
import textwrap
from cpl.utils.string import String
@@ -6,12 +7,12 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
class ApplicationTemplate(TemplateFileABC):
def __init__(self, name: str):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'application.py'
self._path = f'src/{name}/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent("""\
from cpl.application import ApplicationABC
from cpl.configuration import ConfigurationABC

View File

@@ -1,3 +1,4 @@
import os
import textwrap
from cpl.utils.string import String
@@ -6,12 +7,12 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
class NameInitTemplate(TemplateFileABC):
def __init__(self, name: str):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = '__init__.py'
self._path = f'src/{name}/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent("""\
# imports:
""")

View File

@@ -1,3 +1,4 @@
import os.path
import textwrap
from cpl.utils.string import String
@@ -6,12 +7,12 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
def __init__(self, name: str):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = f'src/{name}/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
@@ -44,12 +45,12 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
class MainWithApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = 'src/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
@@ -80,11 +81,11 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
class MainWithoutApplicationBaseTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
self._name = 'main.py'
self._path = 'src/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent("""\
from cpl.console import Console
@@ -112,11 +113,11 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
class MainWithDependencyInjection(TemplateFileABC):
def __init__(self):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
self._name = 'main.py'
self._path = 'src/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent("""\
from cpl.configuration import Configuration, ConfigurationABC
from cpl.console import Console

View File

@@ -1,3 +1,4 @@
import os
import textwrap
from cpl.utils.string import String
@@ -6,12 +7,12 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
class StartupTemplate(TemplateFileABC):
def __init__(self, name: str):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'startup.py'
self._path = f'src/{name}/'
self._path = os.path.join(path, name)
self._value = textwrap.dedent("""\
from cpl.application import StartupABC
from cpl.configuration import ConfigurationABC