Files
mdrs-client-python/mdrsclient/commands/config.py
T
orrisroot 8ce9e09e69 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.
2026-07-02 23:16:53 +09:00

65 lines
2.5 KiB
Python

from argparse import Namespace
from typing import Any, Callable
from mdrsclient.commands.base import BaseCommand
class ConfigCommand(BaseCommand):
@classmethod
def register(cls, parsers: Any) -> None:
# config
config_parser = parsers.add_parser("config", help="configure remote hosts")
func_help: Callable[[Namespace], None] = lambda _: config_parser.print_help()
config_parser.set_defaults(func=func_help)
config_parsers = config_parser.add_subparsers(title="config subcommands")
# config create
create_parser = config_parsers.add_parser("create", help="create a new remote host")
create_parser.add_argument("remote", help="label of remote host")
create_parser.add_argument("url", help="API entrypoint url of remote host")
create_parser.set_defaults(func=cls.func_create)
# config update
update_parser = config_parsers.add_parser("update", help="update a new remote host")
update_parser.add_argument("remote", help="label of remote host")
update_parser.add_argument("url", help="API entrypoint url of remote host")
update_parser.set_defaults(func=cls.func_update)
# config list
list_parser = config_parsers.add_parser("list", help="list all the remote hosts", aliases=["ls"])
list_parser.set_defaults(func=cls.func_list)
# config delete
delete_parser = config_parsers.add_parser(
"delete", help="delete an existing remote host", aliases=["remove", "rm"]
)
delete_parser.add_argument("remote", help="label of remote host")
delete_parser.set_defaults(func=cls.func_delete)
@classmethod
def func_create(cls, args: Namespace) -> None:
remote = str(args.remote)
url = str(args.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)
from mdrsclient.client import MdrsClient
MdrsClient(None).config_update(remote, url)
@classmethod
def func_list(cls, args: Namespace) -> None:
from mdrsclient.client import MdrsClient
client = MdrsClient(None)
for remote, url in client.config_list():
print(f"{remote}:\t{url}")
@classmethod
def func_delete(cls, args: Namespace) -> None:
remote = str(args.remote)
from mdrsclient.client import MdrsClient
MdrsClient(None).config_delete(remote)