2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
6 changed files with 33 additions and 21 deletions
Showing only changes of commit 2c2c1ede21 - Show all commits

View File

@ -22,9 +22,13 @@
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Improved help command">
<list default="true" id="7e2256bc-a6b8-4880-83a6-8b0e3372d0a4" name="Default Changelist" comment="Improved cli">
<change afterPath="$PROJECT_DIR$/src/cpl_cli/error.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl/application/application_abc.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_abc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl/application/application_host.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl/application/application_host.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl_cli/cli.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl_cli/cli.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cpl_cli/command_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cpl_cli/command_handler.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -89,14 +93,14 @@
<recent name="$PROJECT_DIR$/src/cpl/common/application" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/cpl_cli" />
<recent name="$PROJECT_DIR$/src/cpl" />
<recent name="$PROJECT_DIR$/src/cpl/database/connection" />
<recent name="$PROJECT_DIR$/src/cpl/database/context" />
<recent name="$PROJECT_DIR$/src/cpl/database" />
<recent name="$PROJECT_DIR$/src/cpl/common/application" />
</key>
</component>
<component name="RunManager" selected="Python.cli version">
<component name="RunManager" selected="Python.cli help">
<configuration name="cli build" type="PythonConfigurationType" factoryName="Python">
<module name="sh_common_py_lib" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -485,13 +489,6 @@
<option name="presentableId" value="Default" />
<updated>1605881914521</updated>
</task>
<task id="LOCAL-00039" summary="Improved ApplicationHost">
<created>1608047655667</created>
<option name="number" value="00039" />
<option name="presentableId" value="LOCAL-00039" />
<option name="project" value="LOCAL" />
<updated>1608047655667</updated>
</task>
<task id="LOCAL-00040" summary="Improved publisher">
<created>1608048544558</created>
<option name="number" value="00040" />
@ -828,7 +825,14 @@
<option name="project" value="LOCAL" />
<updated>1614797275948</updated>
</task>
<option name="localTasksCounter" value="88" />
<task id="LOCAL-00088" summary="Improved cli">
<created>1614797335732</created>
<option name="number" value="00088" />
<option name="presentableId" value="LOCAL-00088" />
<option name="project" value="LOCAL" />
<updated>1614797335732</updated>
</task>
<option name="localTasksCounter" value="89" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -844,7 +848,6 @@
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Improved error handling" />
<MESSAGE value="Improved service providing" />
<MESSAGE value="Added email client" />
<MESSAGE value="Published" />
@ -869,7 +872,8 @@
<MESSAGE value="Improved application" />
<MESSAGE value="Added version and help cli command" />
<MESSAGE value="Improved help command" />
<option name="LAST_COMMIT_MESSAGE" value="Improved help command" />
<MESSAGE value="Improved cli" />
<option name="LAST_COMMIT_MESSAGE" value="Improved cli" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>

View File

@ -1,3 +1,4 @@
import atexit
from abc import ABC, abstractmethod
from typing import Type, Optional
@ -20,6 +21,10 @@ class ApplicationABC(ABC):
def use_startup(self, startup: Type[StartupABC]):
self._startup = startup()
@staticmethod
def output_at_exit():
atexit.register(Console.close)
def build(self):
if self._startup is not None:
self._app_host = self._startup.create_application_host()

View File

@ -1,4 +1,3 @@
import atexit
from datetime import datetime
from cpl.application.application_host_abc import ApplicationHostABC
@ -6,7 +5,6 @@ from cpl.application.application_runtime import ApplicationRuntime
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration import Configuration
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console
from cpl.dependency_injection.service_provider import ServiceProvider
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
@ -25,8 +23,6 @@ class ApplicationHost(ApplicationHostABC):
self._start_time: datetime = datetime.now()
self._end_time: datetime = datetime.now()
atexit.register(Console.close)
@property
def configuration(self) -> ConfigurationABC:
return self._config

View File

@ -1,9 +1,9 @@
from typing import Optional
from cpl.application.application_abc import ApplicationABC
from cpl.console.console import Console
from cpl_cli.command import Command
from cpl_cli.command_handler import CommandHandler
from cpl_cli.error import Error
from cpl_cli.commands.help import Help
from cpl_cli.commands.version import Version
@ -23,8 +23,7 @@ class CLI(ApplicationABC):
def main(self):
if len(self._configuration.additional_arguments) < 1:
Console.error(f'Expected command')
Console.error('Run \'cpl help\'')
Error.error(f'Expected command')
return
self._command_handler.handle(self._configuration.additional_arguments[0], self._configuration.additional_arguments[1:])

View File

@ -18,5 +18,4 @@ class CommandHandler(ServiceABC):
def handle(self, cmd: str, args: list[str]):
for command in self._commands:
if cmd == command.name or cmd in command.aliases:
print(command.command)
command.command.run(args)

9
src/cpl_cli/error.py Normal file
View File

@ -0,0 +1,9 @@
from cpl.console.console import Console
class Error:
@staticmethod
def error(message: str):
Console.error(message)
Console.error('Run \'cpl help\'')