From f6fc5d09e734fb2d1f73c2b1facfed6222a429e8 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 10 Apr 2021 11:01:56 +0200 Subject: [PATCH] Improved path and name handling in new command --- src/cpl/utils/string.py | 6 +++++- src/cpl_cli/source_creator/console_builder.py | 6 +++++- src/cpl_cli/source_creator/library_builder.py | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cpl/utils/string.py b/src/cpl/utils/string.py index d794f02d..cff170ee 100644 --- a/src/cpl/utils/string.py +++ b/src/cpl/utils/string.py @@ -13,10 +13,14 @@ class String: :param name: :return: """ + # convert to train-case to CamelCase + if '-' in name: + name = ''.join(word.title() for word in name.split('-')) + pattern1 = re.compile(r'(.)([A-Z][a-z]+)') pattern2 = re.compile(r'([a-z0-9])([A-Z])') file_name = re.sub(pattern1, r'\1_\2', name) - return re.sub(pattern2, r'\1_\2', file_name).lower().replace('-', '_') + return re.sub(pattern2, r'\1_\2', file_name).lower() @staticmethod def first_to_upper(string: str) -> str: diff --git a/src/cpl_cli/source_creator/console_builder.py b/src/cpl_cli/source_creator/console_builder.py index 685fed97..41b500b5 100644 --- a/src/cpl_cli/source_creator/console_builder.py +++ b/src/cpl_cli/source_creator/console_builder.py @@ -129,8 +129,12 @@ class ConsoleBuilder: ) for template in templates: + divider = '' + if not template.path.endswith('/'): + divider = '/' + Console.spinner( - f'Creating {proj_name}/{template.path}{template.name}', + f'Creating {proj_name}/{template.path}{divider}{template.name}', TemplateBuilder.build, project_path, template, diff --git a/src/cpl_cli/source_creator/library_builder.py b/src/cpl_cli/source_creator/library_builder.py index 5f28ea7c..b3922a1a 100644 --- a/src/cpl_cli/source_creator/library_builder.py +++ b/src/cpl_cli/source_creator/library_builder.py @@ -129,8 +129,12 @@ class LibraryBuilder: ) for template in templates: + divider = '' + if not template.path.endswith('/'): + divider = '/' + Console.spinner( - f'Creating {proj_name}/{template.path}{template.name}', + f'Creating {proj_name}/{template.path}{divider}{template.name}', TemplateBuilder.build, project_path, template,