2021.4.7 #28

Manually merged
edraft merged 9 commits from 2021.4.7 into 2021.4.post1 2021-04-13 15:47:25 +02:00
18 changed files with 243 additions and 35 deletions

11
scripts/build.sh Normal file
View File

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

11
scripts/publish.sh Normal file
View File

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

View File

@ -104,32 +104,6 @@ class Configuration(ConfigurationABC):
else: else:
self._config[name] = value 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, def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument,
next_arguments: list[str] = None) -> bool: next_arguments: list[str] = None) -> bool:
""" """
@ -246,7 +220,23 @@ class Configuration(ConfigurationABC):
next_args = [] next_args = []
if len(next_arguments) > 1: if len(next_arguments) > 1:
next_args = 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 return result

View File

@ -30,6 +30,7 @@ class CLI(ApplicationABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
self._command_handler: Optional[CommandHandler] = None self._command_handler: Optional[CommandHandler] = None
self._options: list[str] = []
def configure(self): def configure(self):
self._command_handler: CommandHandler = self._services.get_service(CommandHandler) 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('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('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): def main(self):
""" """
Entry point of the CPL CLI Entry point of the CPL CLI
@ -56,14 +60,40 @@ class CLI(ApplicationABC):
command = None command = None
args = [] args = []
if len(self._configuration.additional_arguments) > 0: if len(self._configuration.additional_arguments) > 0:
command = self._configuration.additional_arguments[0] is_option = False
if len(self._configuration.additional_arguments) > 1: for opt in self._options:
args = self._configuration.additional_arguments[1:] 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: else:
for cmd in self._command_handler.commands: for cmd in self._command_handler.commands:
result = self._configuration.get_configuration(cmd.name) result = self._configuration.get_configuration(cmd.name)
result_args = self._configuration.get_configuration(f'{cmd.name}AdditionalArguments') result_args: list[str] = self._configuration.get_configuration(f'{cmd.name}AdditionalArguments')
if result is not None: 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)
if result_args is not None:
for arg in result_args:
args.append(arg)
elif result is not None:
command = cmd.name command = cmd.name
args.append(result) args.append(result)

View File

@ -1,5 +1,6 @@
import json import json
import os.path import os
import textwrap
from typing import Optional from typing import Optional
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
@ -24,6 +25,17 @@ class AddService(CommandABC):
self._workspace = workspace self._workspace = workspace
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Adds a project reference to given project.
Usage: cpl add <source-project> <target-project>
Arguments:
source-project: Name of the project to which the reference has to be
target-project: Name of the project to be referenced
""")
@staticmethod @staticmethod
def _edit_project_file(source: str, project_settings: ProjectSettings, build_settings: BuildSettings): def _edit_project_file(source: str, project_settings: ProjectSettings, build_settings: BuildSettings):
with open(source, 'w') as file: with open(source, 'w') as file:

View File

@ -1,3 +1,5 @@
import textwrap
from cpl_cli.command_abc import CommandABC from cpl_cli.command_abc import CommandABC
from cpl_cli.publish.publisher_abc import PublisherABC from cpl_cli.publish.publisher_abc import PublisherABC
@ -13,6 +15,13 @@ class BuildService(CommandABC):
self._publisher = publisher self._publisher = publisher
@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]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command

View File

@ -1,4 +1,5 @@
import os import os
import textwrap
from collections import Callable from collections import Callable
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
@ -55,6 +56,25 @@ class GenerateService(CommandABC):
self._config = configuration self._config = configuration
self._env = self._config.environment self._env = self._config.environment
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Generate a file based on schematic.
Usage: cpl generate <schematic> <name>
Arguments:
schematic: The schematic to generate.
name: The name of the generated file
Schematics:
abc
class
enum
service
settings
thread
""")
@staticmethod @staticmethod
def _help(message: str): def _help(message: str):
""" """

View File

@ -1,22 +1,55 @@
import textwrap
from typing import Optional
from cpl.console.console import Console from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColorEnum 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 from cpl_cli.command_abc import CommandABC
class HelpService(CommandABC): class HelpService(CommandABC):
def __init__(self): def __init__(self, services: ServiceProviderABC, cmd_handler: CommandHandler):
""" """
Service for CLI command help Service for CLI command help
""" """
CommandABC.__init__(self) CommandABC.__init__(self)
self._services = services
self._commands = cmd_handler.commands
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Lists available command and their short descriptions.
Usage: cpl help <command>
Arguments:
command The command to display the help message for
""")
def run(self, args: list[str]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command
:param args: :param args:
:return: :return:
""" """
if len(args) > 0:
command_name = args[0]
command: Optional[CommandABC] = None
for cmd in self._commands:
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)
return
Console.write_line('Available Commands:') Console.write_line('Available Commands:')
commands = [ commands = [
['add (a|a)', 'Adds a project reference to given project.'], ['add (a|a)', 'Adds a project reference to given project.'],

View File

@ -1,6 +1,7 @@
import json import json
import os import os
import subprocess import subprocess
import textwrap
from packaging import version from packaging import version
@ -39,6 +40,16 @@ class InstallService(CommandABC):
self._project_file = f'{self._config.get_configuration("ProjectName")}.json' self._project_file = f'{self._config.get_configuration("ProjectName")}.json'
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Installs given package via pip
Usage: cpl install <package>
Arguments:
package The package to install
""")
def _install_project(self): def _install_project(self):
""" """
Installs dependencies of CPl project Installs dependencies of CPl project

View File

@ -1,5 +1,6 @@
import os import os
import sys import sys
import textwrap
from typing import Optional from typing import Optional
from packaging import version from packaging import version
@ -46,6 +47,21 @@ class NewService(CommandABC):
self._use_startup: bool = False self._use_startup: bool = False
self._use_service_providing: bool = False self._use_service_providing: bool = False
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Generates a workspace and initial project or add a project to workspace.
Usage: cpl new <type> <name>
Arguments:
type The project type of the initial project
name Name of the workspace or the project
Types:
console
library
""")
@staticmethod @staticmethod
def _help(message: str): def _help(message: str):
""" """

View File

@ -1,3 +1,5 @@
import textwrap
from cpl_cli.command_abc import CommandABC from cpl_cli.command_abc import CommandABC
from cpl_cli.publish.publisher_abc import PublisherABC from cpl_cli.publish.publisher_abc import PublisherABC
@ -13,6 +15,13 @@ class PublishService(CommandABC):
self._publisher = publisher self._publisher = publisher
@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]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command

View File

@ -1,6 +1,7 @@
import os import os
import shutil import shutil
import json import json
import textwrap
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console from cpl.console.console import Console
@ -25,6 +26,16 @@ class RemoveService(CommandABC):
self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings) self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Removes a project from workspace.
Usage: cpl remove <project>
Arguments:
project The name of the project to delete
""")
@staticmethod @staticmethod
def _create_file(file_name: str, content: dict): def _create_file(file_name: str, content: dict):
if not os.path.isabs(file_name): if not os.path.isabs(file_name):

View File

@ -1,3 +1,5 @@
import textwrap
from cpl_cli.command_abc import CommandABC from cpl_cli.command_abc import CommandABC
from cpl_cli.live_server.live_server_service import LiveServerService from cpl_cli.live_server.live_server_service import LiveServerService
@ -13,6 +15,13 @@ class StartService(CommandABC):
self._live_server = live_server self._live_server = live_server
@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]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command

View File

@ -1,6 +1,7 @@
import json import json
import os import os
import subprocess import subprocess
import textwrap
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console from cpl.console.console import Console
@ -31,6 +32,16 @@ class UninstallService(CommandABC):
self._build_settings = build_settings self._build_settings = build_settings
self._project_settings = project_settings self._project_settings = project_settings
@property
def help_message(self) -> str:
return textwrap.dedent("""\
Uninstalls given package via pip
Usage: cpl uninstall <package>
Arguments:
package The package to uninstall
""")
def run(self, args: list[str]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command

View File

@ -1,6 +1,7 @@
import json import json
import os import os
import subprocess import subprocess
import textwrap
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console from cpl.console.console import Console
@ -38,6 +39,13 @@ class UpdateService(CommandABC):
self._project_settings = project_settings self._project_settings = project_settings
self._cli_settings = cli_settings self._cli_settings = cli_settings
@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]: def _collect_project_dependencies(self) -> list[tuple]:
""" """
Collects project dependencies Collects project dependencies

View File

@ -2,6 +2,7 @@ import pkgutil
import sys import sys
import platform import platform
import pkg_resources import pkg_resources
import textwrap
import cpl import cpl
import cpl_cli import cpl_cli
@ -18,6 +19,13 @@ class VersionService(CommandABC):
""" """
CommandABC.__init__(self) CommandABC.__init__(self)
@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]): def run(self, args: list[str]):
""" """
Entry point of command Entry point of command

View File

@ -7,5 +7,9 @@ class CommandABC(ABC):
def __init__(self): def __init__(self):
ABC.__init__(self) ABC.__init__(self)
@property
@abstractmethod
def help_message(self) -> str: pass
@abstractmethod @abstractmethod
def run(self, args: list[str]): pass def run(self, args: list[str]): pass

View File

@ -53,7 +53,9 @@ class Startup(StartupABC):
ConsoleArgument('', 'settings', ['st', 'ST'], ' '), ConsoleArgument('', 'settings', ['st', 'ST'], ' '),
ConsoleArgument('', 'thread', ['t', 't'], ' ') 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( self._configuration.add_console_argument(
ConsoleArgument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True) ConsoleArgument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True)
) )
@ -67,6 +69,9 @@ class Startup(StartupABC):
self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' ')) self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], '')) 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) self._configuration.add_console_arguments(error=False)
return self._configuration return self._configuration