From b63bf41294115b9b8ead24d2540b9849c441f590 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 5 Dec 2022 20:24:15 +0100 Subject: [PATCH] Fixed cpl help #137 --- src/cpl_cli/command/generate_service.py | 105 ++++-------------- src/cpl_cli/command/new_service.py | 27 +---- .../configuration/argument_executable_abc.py | 2 +- src/cpl_core/configuration/configuration.py | 2 +- 4 files changed, 30 insertions(+), 106 deletions(-) diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 41783b66..975770d7 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -28,51 +28,28 @@ class GenerateService(CommandABC): self._config = configuration self._workspace = workspace - self._schematics = {} - # "abc": { - # "Upper": "ABC", - # "Template": ABCTemplate - # }, - # "class": { - # "Upper": "Class", - # "Template": ClassTemplate - # }, - # "enum": { - # "Upper": "Enum", - # "Template": EnumTemplate - # }, - # "pipe": { - # "Upper": "Pipe", - # "Template": PipeTemplate - # }, - # "service": { - # "Upper": "Service", - # "Template": ServiceTemplate - # }, - # "settings": { - # "Upper": "Settings", - # "Template": ConfigModelTemplate - # }, - # "test_case": { - # "Upper": "TestCase", - # "Template": TestCaseTemplate - # }, - # "thread": { - # "Upper": "Thread", - # "Template": ThreadTemplate - # }, - # "validator": { - # "Upper": "Validator", - # "Template": ValidatorTemplate - # } - # } - self._config = configuration self._env = self._config.environment + self._schematics = {} + + self._read_custom_schematics_from_path(self._env.runtime_directory) + self._read_custom_schematics_from_path(self._env.working_directory) + for schematic in GenerateSchematicABC.__subclasses__(): + schematic.register() + + self._schematics = SchematicCollection.get_schematics() @property def help_message(self) -> str: - return textwrap.dedent("""\ + schematics = [] + for schematic in self._schematics: + aliases = '|'.join(self._schematics[schematic]['Aliases']) + schematic_str = schematic + if len(aliases) > 0: + schematic_str = f'{schematic} ({aliases})' + + schematics.append(schematic_str) + help_msg = textwrap.dedent("""\ Generate a file based on schematic. Usage: cpl generate @@ -80,41 +57,11 @@ class GenerateService(CommandABC): schematic: The schematic to generate. name: The name of the generated file - Schematics: - abc - class - enum - pipe - service - settings - test_case - thread - validator - """) + Schematics:""") - @staticmethod - def _help(message: str): - """ - Internal help output - :param message: - :return: - """ - Console.error(message) - - schematics = [ - 'abc (a|A)', - 'class (c|C)', - 'enum (e|E)', - 'pipe (p|P)', - 'service (s|S)', - 'settings (st|ST)', - 'test-case (tc|TC)', - 'thread (t|T)', - 'validator (v|V)' - ] - Console.write_line('Available Schematics:') - for name in schematics: - Console.write(f'\n\t{name} ') + for schematic in schematics: + help_msg += f'\n {schematic}' + return help_msg @staticmethod def _create_file(file_path: str, value: str): @@ -220,12 +167,6 @@ class GenerateService(CommandABC): :param args: :return: """ - self._read_custom_schematics_from_path(self._env.runtime_directory) - self._read_custom_schematics_from_path(self._env.working_directory) - for schematic in GenerateSchematicABC.__subclasses__(): - schematic.register() - self._schematics = SchematicCollection.get_schematics() - schematic = None value = None for s in self._schematics: @@ -241,8 +182,8 @@ class GenerateService(CommandABC): value = args[1] if schematic is None: - self._help('Usage: cpl generate [options]') - Console.write_line() + Console.error(f'Schematic not found') + Console.write_line(self.help_message) sys.exit() name = value diff --git a/src/cpl_cli/command/new_service.py b/src/cpl_cli/command/new_service.py index 9740a324..5715f5cd 100644 --- a/src/cpl_cli/command/new_service.py +++ b/src/cpl_cli/command/new_service.py @@ -67,29 +67,11 @@ class NewService(CommandABC): name Name of the workspace or the project Types: - console - library - unittest + console (c|C) + library (l|L) + unittest (ut|UT) """) - @staticmethod - def _help(message: str): - """ - Internal help output - :param message: - :return: - """ - Console.error(message) - - schematics = [ - 'console (c|C) ', - 'library (l|L) ', - 'unittest (ut|UT) ', - ] - Console.write_line('Available Schematics:') - for name in schematics: - Console.write(f'\n\t{name} ') - def _create_project_settings(self): self._rel_path = os.path.dirname(self._name) self._project_dict = { @@ -369,5 +351,6 @@ class NewService(CommandABC): self._create_venv() else: - self._help('Usage: cpl new [options]') + Console.error(f'Project type not found') + Console.write_line(self.help_message) return diff --git a/src/cpl_core/configuration/argument_executable_abc.py b/src/cpl_core/configuration/argument_executable_abc.py index 8263b338..d7f3319a 100644 --- a/src/cpl_core/configuration/argument_executable_abc.py +++ b/src/cpl_core/configuration/argument_executable_abc.py @@ -7,4 +7,4 @@ class ArgumentExecutableABC(ABC): def __init__(self): pass @abstractmethod - def execute(self, args: list[str]): pass + def run(self, args: list[str]): pass diff --git a/src/cpl_core/configuration/configuration.py b/src/cpl_core/configuration/configuration.py index dbe2574f..f2b8dd5c 100644 --- a/src/cpl_core/configuration/configuration.py +++ b/src/cpl_core/configuration/configuration.py @@ -341,7 +341,7 @@ class Configuration(ConfigurationABC): continue self._additional_arguments.append(arg) - cmd.execute(self._additional_arguments) + cmd.run(self._additional_arguments) self._handle_pre_or_post_executables(False, exe, services) prevent = exe.prevent_next_executable success = True