refactor: extract MdrsClient service layer for library portability
To improve the tool's portability as a Python library, the core logic has been decoupled from the CLI interface. This allows developers to programmatically interact with MDRS without relying on CLI-specific argument parsing or local file-based caches. - Introduce `MdrsClient` service layer to handle core operations. - Abstract authentication state using `CacheInterface` and `InMemoryCache`. - Migrate all CLI commands to utilize `MdrsClient` for execution. - Separate `Doi` data model from API responses and move to `models/doi.py`. - Update `README.md` to include Python API usage examples. - Bump package version to 1.3.17.
This commit is contained in:
@@ -38,13 +38,17 @@ class ConfigCommand(BaseCommand):
|
||||
def func_create(cls, args: Namespace) -> None:
|
||||
remote = str(args.remote)
|
||||
url = str(args.url)
|
||||
cls.create(remote, url)
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
MdrsClient(None).config_create(remote, url)
|
||||
|
||||
@classmethod
|
||||
def func_update(cls, args: Namespace) -> None:
|
||||
remote = str(args.remote)
|
||||
url = str(args.url)
|
||||
cls.update(remote, url)
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
MdrsClient(None).config_update(remote, url)
|
||||
|
||||
@classmethod
|
||||
def func_list(cls, args: Namespace) -> None:
|
||||
@@ -53,7 +57,9 @@ class ConfigCommand(BaseCommand):
|
||||
@classmethod
|
||||
def func_delete(cls, args: Namespace) -> None:
|
||||
remote = str(args.remote)
|
||||
cls.delete(remote)
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
MdrsClient(None).config_delete(remote)
|
||||
|
||||
@classmethod
|
||||
def create(cls, remote: str, url: str) -> None:
|
||||
@@ -75,8 +81,10 @@ class ConfigCommand(BaseCommand):
|
||||
|
||||
@classmethod
|
||||
def list(cls) -> None:
|
||||
config = ConfigFile("")
|
||||
for remote, url in config.list():
|
||||
from mdrsclient.client import MdrsClient
|
||||
|
||||
client = MdrsClient(None)
|
||||
for remote, url in client.config_list():
|
||||
print(f"{remote}:\t{url}")
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user