From 93829027afd46f6ab3d41d39712b3eb5d25f7634 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 11 Apr 2021 16:36:59 +0200 Subject: [PATCH 1/9] Added help message to all cli commands --- src/cpl_cli/command/add_service.py | 8 ++++++- src/cpl_cli/command/build_service.py | 7 ++++++ src/cpl_cli/command/generate_service.py | 6 +++++ src/cpl_cli/command/help_service.py | 29 +++++++++++++++++++++++- src/cpl_cli/command/install_service.py | 6 +++++ src/cpl_cli/command/new_service.py | 6 +++++ src/cpl_cli/command/publish_service.py | 7 ++++++ src/cpl_cli/command/remove_service.py | 6 +++++ src/cpl_cli/command/start_service.py | 7 ++++++ src/cpl_cli/command/uninstall_service.py | 6 +++++ src/cpl_cli/command/update_service.py | 6 +++++ src/cpl_cli/command/version_service.py | 6 +++++ src/cpl_cli/command_abc.py | 4 ++++ src/cpl_cli/startup.py | 4 +++- 14 files changed, 105 insertions(+), 3 deletions(-) diff --git a/src/cpl_cli/command/add_service.py b/src/cpl_cli/command/add_service.py index ea4c8738..612038a0 100644 --- a/src/cpl_cli/command/add_service.py +++ b/src/cpl_cli/command/add_service.py @@ -1,5 +1,6 @@ import json -import os.path +import os +import textwrap from typing import Optional from cpl.configuration.configuration_abc import ConfigurationABC @@ -24,6 +25,11 @@ class AddService(CommandABC): self._workspace = workspace + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + @staticmethod def _edit_project_file(source: str, project_settings: ProjectSettings, build_settings: BuildSettings): with open(source, 'w') as file: diff --git a/src/cpl_cli/command/build_service.py b/src/cpl_cli/command/build_service.py index 18ce4dbd..703b54ac 100644 --- a/src/cpl_cli/command/build_service.py +++ b/src/cpl_cli/command/build_service.py @@ -1,3 +1,5 @@ +import textwrap + from cpl_cli.command_abc import CommandABC from cpl_cli.publish.publisher_abc import PublisherABC @@ -13,6 +15,11 @@ class BuildService(CommandABC): self._publisher = publisher + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 3358d681..5078a23a 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -1,4 +1,5 @@ import os +import textwrap from collections import Callable from cpl.configuration.configuration_abc import ConfigurationABC @@ -55,6 +56,11 @@ class GenerateService(CommandABC): self._config = configuration self._env = self._config.environment + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + @staticmethod def _help(message: str): """ diff --git a/src/cpl_cli/command/help_service.py b/src/cpl_cli/command/help_service.py index fb96a419..a93f8de2 100644 --- a/src/cpl_cli/command/help_service.py +++ b/src/cpl_cli/command/help_service.py @@ -1,22 +1,49 @@ +import textwrap +from typing import Optional + from cpl.console.console import Console from cpl.console.foreground_color_enum import ForegroundColorEnum +from cpl.dependency_injection.service_provider_abc import ServiceProviderABC +from cpl_cli.command_handler_service import CommandHandler from cpl_cli.command_abc import CommandABC class HelpService(CommandABC): - def __init__(self): + def __init__(self, services: ServiceProviderABC, cmd_handler: CommandHandler): """ Service for CLI command help """ CommandABC.__init__(self) + self._services = services + self._commands = cmd_handler.commands + + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command :param args: :return: """ + if len(args) > 0: + command_name = args[0] + command: Optional[CommandABC] = None + for cmd in self._commands: + if cmd.name == command_name: + command = self._services.get_service(cmd.command) + + if command is None: + Console.error(f'Invalid argument: {command_name}') + + Console.write_line(command.help_message) + + return + Console.write_line('Available Commands:') commands = [ ['add (a|a)', 'Adds a project reference to given project.'], diff --git a/src/cpl_cli/command/install_service.py b/src/cpl_cli/command/install_service.py index 2178e735..282d0562 100644 --- a/src/cpl_cli/command/install_service.py +++ b/src/cpl_cli/command/install_service.py @@ -1,6 +1,7 @@ import json import os import subprocess +import textwrap from packaging import version @@ -39,6 +40,11 @@ class InstallService(CommandABC): self._project_file = f'{self._config.get_configuration("ProjectName")}.json' + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def _install_project(self): """ Installs dependencies of CPl project diff --git a/src/cpl_cli/command/new_service.py b/src/cpl_cli/command/new_service.py index 20c3bb22..9a7c9b19 100644 --- a/src/cpl_cli/command/new_service.py +++ b/src/cpl_cli/command/new_service.py @@ -1,5 +1,6 @@ import os import sys +import textwrap from typing import Optional from packaging import version @@ -46,6 +47,11 @@ class NewService(CommandABC): self._use_startup: bool = False self._use_service_providing: bool = False + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + @staticmethod def _help(message: str): """ diff --git a/src/cpl_cli/command/publish_service.py b/src/cpl_cli/command/publish_service.py index b46474cb..6f1e2c5f 100644 --- a/src/cpl_cli/command/publish_service.py +++ b/src/cpl_cli/command/publish_service.py @@ -1,3 +1,5 @@ +import textwrap + from cpl_cli.command_abc import CommandABC from cpl_cli.publish.publisher_abc import PublisherABC @@ -13,6 +15,11 @@ class PublishService(CommandABC): self._publisher = publisher + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command diff --git a/src/cpl_cli/command/remove_service.py b/src/cpl_cli/command/remove_service.py index 89457e57..378237d5 100644 --- a/src/cpl_cli/command/remove_service.py +++ b/src/cpl_cli/command/remove_service.py @@ -1,6 +1,7 @@ import os import shutil import json +import textwrap from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console @@ -25,6 +26,11 @@ class RemoveService(CommandABC): self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings) + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + @staticmethod def _create_file(file_name: str, content: dict): if not os.path.isabs(file_name): diff --git a/src/cpl_cli/command/start_service.py b/src/cpl_cli/command/start_service.py index 388846f1..4e42fea6 100644 --- a/src/cpl_cli/command/start_service.py +++ b/src/cpl_cli/command/start_service.py @@ -1,3 +1,5 @@ +import textwrap + from cpl_cli.command_abc import CommandABC from cpl_cli.live_server.live_server_service import LiveServerService @@ -13,6 +15,11 @@ class StartService(CommandABC): self._live_server = live_server + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command diff --git a/src/cpl_cli/command/uninstall_service.py b/src/cpl_cli/command/uninstall_service.py index 8e091766..ade17dd6 100644 --- a/src/cpl_cli/command/uninstall_service.py +++ b/src/cpl_cli/command/uninstall_service.py @@ -1,6 +1,7 @@ import json import os import subprocess +import textwrap from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console @@ -31,6 +32,11 @@ class UninstallService(CommandABC): self._build_settings = build_settings self._project_settings = project_settings + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command diff --git a/src/cpl_cli/command/update_service.py b/src/cpl_cli/command/update_service.py index eef18f80..c5a31ba4 100644 --- a/src/cpl_cli/command/update_service.py +++ b/src/cpl_cli/command/update_service.py @@ -1,6 +1,7 @@ import json import os import subprocess +import textwrap from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console @@ -38,6 +39,11 @@ class UpdateService(CommandABC): self._project_settings = project_settings self._cli_settings = cli_settings + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def _collect_project_dependencies(self) -> list[tuple]: """ Collects project dependencies diff --git a/src/cpl_cli/command/version_service.py b/src/cpl_cli/command/version_service.py index 0046a3f9..cde683e9 100644 --- a/src/cpl_cli/command/version_service.py +++ b/src/cpl_cli/command/version_service.py @@ -2,6 +2,7 @@ import pkgutil import sys import platform import pkg_resources +import textwrap import cpl import cpl_cli @@ -18,6 +19,11 @@ class VersionService(CommandABC): """ CommandABC.__init__(self) + @property + def help_message(self) -> str: + return textwrap.dedent("""\ + """) + def run(self, args: list[str]): """ Entry point of command diff --git a/src/cpl_cli/command_abc.py b/src/cpl_cli/command_abc.py index 6ac6376f..9cdfd84b 100644 --- a/src/cpl_cli/command_abc.py +++ b/src/cpl_cli/command_abc.py @@ -7,5 +7,9 @@ class CommandABC(ABC): def __init__(self): ABC.__init__(self) + @property + @abstractmethod + def help_message(self) -> str: pass + @abstractmethod def run(self, args: list[str]): pass diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py index 84e77c8d..f380b050 100644 --- a/src/cpl_cli/startup.py +++ b/src/cpl_cli/startup.py @@ -53,7 +53,9 @@ class Startup(StartupABC): ConsoleArgument('', 'settings', ['st', 'ST'], ' '), ConsoleArgument('', 'thread', ['t', 't'], ' ') ])) - self._configuration.add_console_argument(ConsoleArgument('', 'help', ['h', 'H'], '')) + self._configuration.add_console_argument( + ConsoleArgument('', 'help', ['h', 'H'], ' ', is_value_token_optional=True) + ) self._configuration.add_console_argument( ConsoleArgument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True) ) From d94b25d9d8c7f5306b52b80d6e55588bd3a1e62d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 19:43:30 +0200 Subject: [PATCH 2/9] Improved configuration console argument handling --- src/cpl/configuration/configuration.py | 44 ++++++++++---------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/cpl/configuration/configuration.py b/src/cpl/configuration/configuration.py index 72959a94..4c7edc7b 100644 --- a/src/cpl/configuration/configuration.py +++ b/src/cpl/configuration/configuration.py @@ -104,32 +104,6 @@ class Configuration(ConfigurationABC): else: self._config[name] = value - def _validate_argument_child(self, argument: str, argument_type: ConsoleArgument, - next_arguments: Optional[list[str]]) -> bool: - """ - Validates the child arguments of argument - :param argument: - :param argument_type: - :param next_arguments: - :return: - """ - if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0: - found = False - for child_argument_type in argument_type.console_arguments: - found = self._validate_argument_by_argument_type(argument, child_argument_type, next_arguments) - if found and child_argument_type.name not in self._additional_arguments: - self._additional_arguments.append(child_argument_type.name) - - if found: - break - - if not found: - raise Exception(f'Invalid argument: {argument}') - - return found - - return True - def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument, next_arguments: list[str] = None) -> bool: """ @@ -246,7 +220,23 @@ class Configuration(ConfigurationABC): next_args = [] if len(next_arguments) > 1: next_args = next_arguments[1:] - result = self._validate_argument_child(next_arguments[0], argument_type, next_args) + + if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0: + found_child = False + for child_argument_type in argument_type.console_arguments: + found_child = self._validate_argument_by_argument_type( + next_arguments[0], + child_argument_type, + next_args + ) + if found_child and child_argument_type.name not in self._additional_arguments: + self._additional_arguments.append(child_argument_type.name) + + if found_child: + break + + if not found_child: + result = self._validate_argument_by_argument_type(next_arguments[0], argument_type, next_args) return result From 696c62292b06bb3ceafb150d70057b7b5e31a5c0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 19:43:55 +0200 Subject: [PATCH 3/9] Added logic to cli to use --help option for help command --- src/cpl_cli/cli.py | 19 ++++++++++++++++--- src/cpl_cli/startup.py | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index 145abc12..28f06cf4 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -30,6 +30,7 @@ class CLI(ApplicationABC): ApplicationABC.__init__(self, config, services) self._command_handler: Optional[CommandHandler] = None + self._options: list[str] = [] def configure(self): self._command_handler: CommandHandler = self._services.get_service(CommandHandler) @@ -47,6 +48,9 @@ class CLI(ApplicationABC): self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, False, True, True)) self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False, False, False)) + self._command_handler.add_command(CommandModel('--help', ['-h', '-H'], HelpService, False, False, False)) + self._options.append('--help') + def main(self): """ Entry point of the CPL CLI @@ -56,9 +60,18 @@ class CLI(ApplicationABC): command = None args = [] if len(self._configuration.additional_arguments) > 0: - command = self._configuration.additional_arguments[0] - if len(self._configuration.additional_arguments) > 1: - args = self._configuration.additional_arguments[1:] + is_option = False + for opt in self._options: + if opt in self._configuration.additional_arguments: + is_option = True + command = opt + args = self._configuration.additional_arguments + args.remove(opt) + + if not is_option: + command = self._configuration.additional_arguments[0] + if len(self._configuration.additional_arguments) > 1: + args = self._configuration.additional_arguments[1:] else: for cmd in self._command_handler.commands: result = self._configuration.get_configuration(cmd.name) diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py index f380b050..3e0cf9c9 100644 --- a/src/cpl_cli/startup.py +++ b/src/cpl_cli/startup.py @@ -69,6 +69,9 @@ class Startup(StartupABC): self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' ')) self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], '')) + + self._configuration.add_console_argument(ConsoleArgument('', '--help', ['-h', '-H'], '')) + self._configuration.add_console_arguments(error=False) return self._configuration From f8f5d46491c42bee223af3696a3c766368959be9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 19:44:29 +0200 Subject: [PATCH 4/9] Added help message to generate command --- src/cpl_cli/command/generate_service.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 5078a23a..40e913a0 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -59,6 +59,20 @@ class GenerateService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Generate a file based on schematic. + usage: cpl generate + + arguments: + schematic: The schematic to generate. + name: The name of the generated file + + schematics: + abc + class + enum + service + settings + thread """) @staticmethod From 7eca382cb3949a9ab906421203e6fa5680c46f26 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 20:02:45 +0200 Subject: [PATCH 5/9] Added help messages to cli commands --- src/cpl_cli/command/add_service.py | 6 ++++++ src/cpl_cli/command/build_service.py | 2 ++ src/cpl_cli/command/help_service.py | 5 +++++ src/cpl_cli/command/install_service.py | 5 +++++ src/cpl_cli/command/new_service.py | 10 ++++++++++ src/cpl_cli/command/publish_service.py | 2 ++ src/cpl_cli/command/remove_service.py | 5 +++++ src/cpl_cli/command/start_service.py | 2 ++ src/cpl_cli/command/uninstall_service.py | 5 +++++ src/cpl_cli/command/update_service.py | 2 ++ src/cpl_cli/command/version_service.py | 2 ++ 11 files changed, 46 insertions(+) diff --git a/src/cpl_cli/command/add_service.py b/src/cpl_cli/command/add_service.py index 612038a0..c13daee2 100644 --- a/src/cpl_cli/command/add_service.py +++ b/src/cpl_cli/command/add_service.py @@ -28,6 +28,12 @@ class AddService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Adds a project reference to given project. + usage: cpl add + + arguments: + source-project: Name of the project to which the reference has to be + target-project: Name of the project to be referenced """) @staticmethod diff --git a/src/cpl_cli/command/build_service.py b/src/cpl_cli/command/build_service.py index 703b54ac..31eab2b7 100644 --- a/src/cpl_cli/command/build_service.py +++ b/src/cpl_cli/command/build_service.py @@ -18,6 +18,8 @@ class BuildService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Copies an python app into an output directory named build/ at the given output path. Must be executed within a CPL workspace or project directory + usage: cpl build """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/help_service.py b/src/cpl_cli/command/help_service.py index a93f8de2..6eb77411 100644 --- a/src/cpl_cli/command/help_service.py +++ b/src/cpl_cli/command/help_service.py @@ -22,6 +22,11 @@ class HelpService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Lists available command and their short descriptions. + usage: cpl help + + Arguments: + command The command to display the help message for """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/install_service.py b/src/cpl_cli/command/install_service.py index 282d0562..32c558ab 100644 --- a/src/cpl_cli/command/install_service.py +++ b/src/cpl_cli/command/install_service.py @@ -43,6 +43,11 @@ class InstallService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Installs given package via pip + usage: cpl install + + Arguments: + package The package to install """) def _install_project(self): diff --git a/src/cpl_cli/command/new_service.py b/src/cpl_cli/command/new_service.py index 9a7c9b19..792f4a62 100644 --- a/src/cpl_cli/command/new_service.py +++ b/src/cpl_cli/command/new_service.py @@ -50,6 +50,16 @@ class NewService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Generates a workspace and initial project or add a project to workspace. + usage: cpl new + + Arguments: + type The project type of the initial project + name Name of the workspace or the project + + Types: + console + library """) @staticmethod diff --git a/src/cpl_cli/command/publish_service.py b/src/cpl_cli/command/publish_service.py index 6f1e2c5f..e4706df2 100644 --- a/src/cpl_cli/command/publish_service.py +++ b/src/cpl_cli/command/publish_service.py @@ -18,6 +18,8 @@ class PublishService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Prepares files for publish into an output directory named dist/ at the given output path and executes setup.py. + usage: cpl publish """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/remove_service.py b/src/cpl_cli/command/remove_service.py index 378237d5..8d5c9f31 100644 --- a/src/cpl_cli/command/remove_service.py +++ b/src/cpl_cli/command/remove_service.py @@ -29,6 +29,11 @@ class RemoveService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Removes a project from workspace. + usage: cpl add + + Arguments: + project The name of the project to delete """) @staticmethod diff --git a/src/cpl_cli/command/start_service.py b/src/cpl_cli/command/start_service.py index 4e42fea6..2572b2bb 100644 --- a/src/cpl_cli/command/start_service.py +++ b/src/cpl_cli/command/start_service.py @@ -18,6 +18,8 @@ class StartService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Starts your application, restarting on file changes. + usage: cpl start """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/uninstall_service.py b/src/cpl_cli/command/uninstall_service.py index ade17dd6..82a12444 100644 --- a/src/cpl_cli/command/uninstall_service.py +++ b/src/cpl_cli/command/uninstall_service.py @@ -35,6 +35,11 @@ class UninstallService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Uninstalls given package via pip + usage: cpl uninstall + + Arguments: + package The package to uninstall """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/update_service.py b/src/cpl_cli/command/update_service.py index c5a31ba4..c5842ad1 100644 --- a/src/cpl_cli/command/update_service.py +++ b/src/cpl_cli/command/update_service.py @@ -42,6 +42,8 @@ class UpdateService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Updates the CPL and project dependencies. + usage: cpl update """) def _collect_project_dependencies(self) -> list[tuple]: diff --git a/src/cpl_cli/command/version_service.py b/src/cpl_cli/command/version_service.py index cde683e9..776f3746 100644 --- a/src/cpl_cli/command/version_service.py +++ b/src/cpl_cli/command/version_service.py @@ -22,6 +22,8 @@ class VersionService(CommandABC): @property def help_message(self) -> str: return textwrap.dedent("""\ + Lists the version of CPL, CPL CLI and all installed packages from pip. + usage: cpl version """) def run(self, args: list[str]): From 8f3ee539153cddd1658166a8fc66c541d6af56d0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 20:05:55 +0200 Subject: [PATCH 6/9] Fixed typos --- src/cpl_cli/command/add_service.py | 4 ++-- src/cpl_cli/command/build_service.py | 2 +- src/cpl_cli/command/generate_service.py | 6 +++--- src/cpl_cli/command/help_service.py | 2 +- src/cpl_cli/command/install_service.py | 2 +- src/cpl_cli/command/new_service.py | 2 +- src/cpl_cli/command/publish_service.py | 2 +- src/cpl_cli/command/remove_service.py | 2 +- src/cpl_cli/command/start_service.py | 2 +- src/cpl_cli/command/uninstall_service.py | 2 +- src/cpl_cli/command/update_service.py | 2 +- src/cpl_cli/command/version_service.py | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cpl_cli/command/add_service.py b/src/cpl_cli/command/add_service.py index c13daee2..30d2dd17 100644 --- a/src/cpl_cli/command/add_service.py +++ b/src/cpl_cli/command/add_service.py @@ -29,9 +29,9 @@ class AddService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Adds a project reference to given project. - usage: cpl add + Usage: cpl add - arguments: + Arguments: source-project: Name of the project to which the reference has to be target-project: Name of the project to be referenced """) diff --git a/src/cpl_cli/command/build_service.py b/src/cpl_cli/command/build_service.py index 31eab2b7..5fe1bc72 100644 --- a/src/cpl_cli/command/build_service.py +++ b/src/cpl_cli/command/build_service.py @@ -19,7 +19,7 @@ class BuildService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Copies an python app into an output directory named build/ at the given output path. Must be executed within a CPL workspace or project directory - usage: cpl build + Usage: cpl build """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 40e913a0..0b7503be 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -60,13 +60,13 @@ class GenerateService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Generate a file based on schematic. - usage: cpl generate + Usage: cpl generate - arguments: + Arguments: schematic: The schematic to generate. name: The name of the generated file - schematics: + Schematics: abc class enum diff --git a/src/cpl_cli/command/help_service.py b/src/cpl_cli/command/help_service.py index 6eb77411..566b0260 100644 --- a/src/cpl_cli/command/help_service.py +++ b/src/cpl_cli/command/help_service.py @@ -23,7 +23,7 @@ class HelpService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Lists available command and their short descriptions. - usage: cpl help + Usage: cpl help Arguments: command The command to display the help message for diff --git a/src/cpl_cli/command/install_service.py b/src/cpl_cli/command/install_service.py index 32c558ab..7f733e2f 100644 --- a/src/cpl_cli/command/install_service.py +++ b/src/cpl_cli/command/install_service.py @@ -44,7 +44,7 @@ class InstallService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Installs given package via pip - usage: cpl install + Usage: cpl install Arguments: package The package to install diff --git a/src/cpl_cli/command/new_service.py b/src/cpl_cli/command/new_service.py index 792f4a62..8c19b346 100644 --- a/src/cpl_cli/command/new_service.py +++ b/src/cpl_cli/command/new_service.py @@ -51,7 +51,7 @@ class NewService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Generates a workspace and initial project or add a project to workspace. - usage: cpl new + Usage: cpl new Arguments: type The project type of the initial project diff --git a/src/cpl_cli/command/publish_service.py b/src/cpl_cli/command/publish_service.py index e4706df2..7a6403a4 100644 --- a/src/cpl_cli/command/publish_service.py +++ b/src/cpl_cli/command/publish_service.py @@ -19,7 +19,7 @@ class PublishService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Prepares files for publish into an output directory named dist/ at the given output path and executes setup.py. - usage: cpl publish + Usage: cpl publish """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/remove_service.py b/src/cpl_cli/command/remove_service.py index 8d5c9f31..d826d907 100644 --- a/src/cpl_cli/command/remove_service.py +++ b/src/cpl_cli/command/remove_service.py @@ -30,7 +30,7 @@ class RemoveService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Removes a project from workspace. - usage: cpl add + Usage: cpl remove Arguments: project The name of the project to delete diff --git a/src/cpl_cli/command/start_service.py b/src/cpl_cli/command/start_service.py index 2572b2bb..48b853b4 100644 --- a/src/cpl_cli/command/start_service.py +++ b/src/cpl_cli/command/start_service.py @@ -19,7 +19,7 @@ class StartService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Starts your application, restarting on file changes. - usage: cpl start + Usage: cpl start """) def run(self, args: list[str]): diff --git a/src/cpl_cli/command/uninstall_service.py b/src/cpl_cli/command/uninstall_service.py index 82a12444..4c9944c6 100644 --- a/src/cpl_cli/command/uninstall_service.py +++ b/src/cpl_cli/command/uninstall_service.py @@ -36,7 +36,7 @@ class UninstallService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Uninstalls given package via pip - usage: cpl uninstall + Usage: cpl uninstall Arguments: package The package to uninstall diff --git a/src/cpl_cli/command/update_service.py b/src/cpl_cli/command/update_service.py index c5842ad1..5cfb52de 100644 --- a/src/cpl_cli/command/update_service.py +++ b/src/cpl_cli/command/update_service.py @@ -43,7 +43,7 @@ class UpdateService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Updates the CPL and project dependencies. - usage: cpl update + Usage: cpl update """) def _collect_project_dependencies(self) -> list[tuple]: diff --git a/src/cpl_cli/command/version_service.py b/src/cpl_cli/command/version_service.py index 776f3746..5afadbd2 100644 --- a/src/cpl_cli/command/version_service.py +++ b/src/cpl_cli/command/version_service.py @@ -23,7 +23,7 @@ class VersionService(CommandABC): def help_message(self) -> str: return textwrap.dedent("""\ Lists the version of CPL, CPL CLI and all installed packages from pip. - usage: cpl version + Usage: cpl version """) def run(self, args: list[str]): From d34d5015206f56d892816c4217aba96694ba1057 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Apr 2021 20:22:28 +0200 Subject: [PATCH 7/9] Bugfixes for help command --- src/cpl_cli/cli.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index 28f06cf4..5ecb010f 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -75,8 +75,24 @@ class CLI(ApplicationABC): else: for cmd in self._command_handler.commands: result = self._configuration.get_configuration(cmd.name) - result_args = self._configuration.get_configuration(f'{cmd.name}AdditionalArguments') - if result is not None: + result_args: list[str] = self._configuration.get_configuration(f'{cmd.name}AdditionalArguments') + is_option = False + for opt in self._options: + if opt == result: + is_option = True + command = opt + + elif result_args is not None and opt in result_args: + is_option = True + command = opt + result_args.remove(opt) + + if is_option: + args.append(cmd.name) + for arg in result_args: + args.append(arg) + + elif result is not None: command = cmd.name args.append(result) From 602c48bc0656741f98858689dd5db0bbc87fd7eb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 13 Apr 2021 15:27:19 +0200 Subject: [PATCH 8/9] Bugfixes for help command handling --- src/cpl_cli/cli.py | 5 +++-- src/cpl_cli/command/help_service.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index 5ecb010f..a4e029f7 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -89,8 +89,9 @@ class CLI(ApplicationABC): if is_option: args.append(cmd.name) - for arg in result_args: - args.append(arg) + if result_args is not None: + for arg in result_args: + args.append(arg) elif result is not None: command = cmd.name diff --git a/src/cpl_cli/command/help_service.py b/src/cpl_cli/command/help_service.py index 566b0260..50e98921 100644 --- a/src/cpl_cli/command/help_service.py +++ b/src/cpl_cli/command/help_service.py @@ -39,11 +39,12 @@ class HelpService(CommandABC): command_name = args[0] command: Optional[CommandABC] = None for cmd in self._commands: - if cmd.name == command_name: + if cmd.name == command_name or command_name in cmd.aliases: command = self._services.get_service(cmd.command) if command is None: Console.error(f'Invalid argument: {command_name}') + return Console.write_line(command.help_message) From ae39d43ea921dac3ef53778d3af5d4a41061d575 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 13 Apr 2021 15:43:05 +0200 Subject: [PATCH 9/9] Added useful deployment scripts & closed #22 --- scripts/build.sh | 11 +++++++++++ scripts/publish.sh | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 scripts/build.sh create mode 100644 scripts/publish.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 00000000..bccdac52 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# activate venv +source /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/cpl-env/bin/activate + +# CLI +cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/ +cpl build + +# CPL +cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl +cpl build \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 00000000..341a279c --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# activate venv +source /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/cpl-env/bin/activate + +# CLI +cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/ +cpl publish + +# CPL +cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl +cpl publish \ No newline at end of file