mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 21:08:03 +00:00
cmdeploy: replace globals() subcommand scan with explicit SUBCOMMANDS list
The get_parser() loop that scanned globals() for *_cmd names was fragile and forced # noqa: F401 on all lxc imports (ruff couldn't see they were used dynamically). Replace it with an explicit SUBCOMMANDS list of (cmd_func, options_func, needs_config) tuples. This makes the full set of subcommands visible at a glance, their registration order defined, and the imports unconditionally used (no more noqa suppressions).
This commit is contained in:
@@ -16,8 +16,8 @@ import pyinfra
|
|||||||
from chatmaild.config import read_config, write_initial_config
|
from chatmaild.config import read_config, write_initial_config
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from . import dns, remote # noqa: F401
|
from . import dns, remote
|
||||||
from .lxc.cli import ( # noqa: F401
|
from .lxc.cli import (
|
||||||
lxc_start_cmd,
|
lxc_start_cmd,
|
||||||
lxc_start_cmd_options,
|
lxc_start_cmd_options,
|
||||||
lxc_status_cmd,
|
lxc_status_cmd,
|
||||||
@@ -379,6 +379,23 @@ Setup your chatmail server configuration and
|
|||||||
deploy it via SSH to your remote location.
|
deploy it via SSH to your remote location.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Explicit subcommand registry: (cmd_func, options_func_or_None, needs_config).
|
||||||
|
# LXC commands don't need a chatmail.ini (no config); all others do.
|
||||||
|
SUBCOMMANDS = [
|
||||||
|
(init_cmd, init_cmd_options, True),
|
||||||
|
(run_cmd, run_cmd_options, True),
|
||||||
|
(dns_cmd, dns_cmd_options, True),
|
||||||
|
(status_cmd, status_cmd_options, True),
|
||||||
|
(test_cmd, test_cmd_options, True),
|
||||||
|
(fmt_cmd, fmt_cmd_options, True),
|
||||||
|
(bench_cmd, None, True),
|
||||||
|
(webdev_cmd, None, True),
|
||||||
|
(lxc_start_cmd, lxc_start_cmd_options, False),
|
||||||
|
(lxc_stop_cmd, lxc_stop_cmd_options, False),
|
||||||
|
(lxc_status_cmd, lxc_status_cmd_options, False),
|
||||||
|
(lxc_test_cmd, lxc_test_cmd_options, False),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_parser():
|
def get_parser():
|
||||||
"""Return an ArgumentParser for the 'cmdeploy' CLI"""
|
"""Return an ArgumentParser for the 'cmdeploy' CLI"""
|
||||||
@@ -395,15 +412,10 @@ def get_parser():
|
|||||||
)
|
)
|
||||||
subparsers = parser.add_subparsers(title="subcommands")
|
subparsers = parser.add_subparsers(title="subcommands")
|
||||||
|
|
||||||
# find all subcommands in the module namespace
|
for func, addopts, needs_config in SUBCOMMANDS:
|
||||||
glob = globals()
|
subparser = add_subcommand(subparsers, func, add_config=needs_config)
|
||||||
for name, func in glob.items():
|
if addopts is not None:
|
||||||
if name.endswith("_cmd"):
|
addopts(subparser)
|
||||||
needs_config = not name.startswith("lxc_")
|
|
||||||
subparser = add_subcommand(subparsers, func, add_config=needs_config)
|
|
||||||
addopts = glob.get(name + "_options")
|
|
||||||
if addopts is not None:
|
|
||||||
addopts(subparser)
|
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user