refactor: use services layer and modularize transfer operations
Decouple CLI commands from internal helper logic and consolidate the core file transfer operations in the service layer to improve library portability. - Make MdrsClient subclass MdrsService to inherit resource resolution. - Remove all deprecated helper methods from BaseCommand. - Move core upload and download logic to a new transfer module. - Refactor all CLI commands to route actions through MdrsClient. - Eliminate circular imports between client and CLI command modules.
This commit is contained in:
@@ -2,8 +2,6 @@ from argparse import Namespace
|
||||
from typing import Any, Callable
|
||||
|
||||
from mdrsclient.commands.base import BaseCommand
|
||||
from mdrsclient.config import ConfigFile
|
||||
from mdrsclient.exceptions import IllegalArgumentException
|
||||
|
||||
|
||||
class ConfigCommand(BaseCommand):
|
||||
@@ -52,35 +50,6 @@ class ConfigCommand(BaseCommand):
|
||||
|
||||
@classmethod
|
||||
def func_list(cls, args: Namespace) -> None:
|
||||
cls.list()
|
||||
|
||||
@classmethod
|
||||
def func_delete(cls, args: Namespace) -> None:
|
||||
remote = str(args.remote)
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
MdrsClient(None).config_delete(remote)
|
||||
|
||||
@classmethod
|
||||
def create(cls, remote: str, url: str) -> None:
|
||||
remote = cls._parse_remote_host(remote)
|
||||
config = ConfigFile(remote)
|
||||
if config.url is not None:
|
||||
raise IllegalArgumentException(f"Remote host `{remote}` is already exists.")
|
||||
else:
|
||||
config.url = url
|
||||
|
||||
@classmethod
|
||||
def update(cls, remote: str, url: str) -> None:
|
||||
remote = cls._parse_remote_host(remote)
|
||||
config = ConfigFile(remote)
|
||||
if config.url is None:
|
||||
raise IllegalArgumentException(f"Remote host `{remote}` is not exists.")
|
||||
else:
|
||||
config.url = url
|
||||
|
||||
@classmethod
|
||||
def list(cls) -> None:
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
client = MdrsClient(None)
|
||||
@@ -88,10 +57,8 @@ class ConfigCommand(BaseCommand):
|
||||
print(f"{remote}:\t{url}")
|
||||
|
||||
@classmethod
|
||||
def delete(cls, remote: str) -> None:
|
||||
remote = cls._parse_remote_host(remote)
|
||||
config = ConfigFile(remote)
|
||||
if config.url is None:
|
||||
raise IllegalArgumentException(f"Remote host `{remote}` is not exists.")
|
||||
else:
|
||||
del config.url
|
||||
def func_delete(cls, args: Namespace) -> None:
|
||||
remote = str(args.remote)
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
MdrsClient(None).config_delete(remote)
|
||||
|
||||
Reference in New Issue
Block a user