aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/cli/dispatch.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-24 18:19:13 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-24 18:19:13 +0200
commit6e9afe3e54ab6fb0162393150b7892655b4561d4 (patch)
treef1cf20d891bf0d75dd206953bcec781f47ab7b15 /packages/meshbay-node/src/meshbay_node/cli/dispatch.py
parenta408a25af7b91abf729ec5fac7e5506437a86049 (diff)
downloadmeshbay-6e9afe3e54ab6fb0162393150b7892655b4561d4.tar.gz
refactor(node): move the CLI out of daemon.py into cli/
Each `if args.command == ...` branch of main() becomes a function in cli/ (one module per family of verbs); the parser, the process setup and a VERBS table go to cli/parser.py and cli/dispatch.py. daemon.main runs the verb or starts the daemon. Tests patch the CLI through conftest.patch_cli; the CLI golden is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/cli/dispatch.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/cli/dispatch.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/cli/dispatch.py b/packages/meshbay-node/src/meshbay_node/cli/dispatch.py
new file mode 100644
index 0000000..849d589
--- /dev/null
+++ b/packages/meshbay-node/src/meshbay_node/cli/dispatch.py
@@ -0,0 +1,68 @@
+"""From the command line to the verb that runs it."""
+
+import logging
+
+from meshbay_node.cli import content, groups, lifecycle, members, settings, setup, status
+from meshbay_node.cli.parser import build_parser
+from meshbay_node.platform import config_dir
+
+
+def start():
+ """Set up the process and read its command line."""
+ from meshbay_node.platform import configure_event_loop, force_utf8_stdio, load_node_env
+ force_utf8_stdio()
+ configure_event_loop()
+ # Before anything reads the environment. On Linux systemd has usually loaded
+ # the same file already via EnvironmentFile=; this is what makes a Windows
+ # run (Startup-folder .vbs, no systemd) and a bare `meshbay-node` behave the
+ # same. Already-set variables are left alone, so it cannot undo either.
+ load_node_env(config_dir())
+
+ parser = build_parser()
+ args = parser.parse_args()
+
+ # Query commands print a report; library logging would interleave with it.
+ quiet = args.command in ("status", "gek-init", "gek", "operator",
+ "member", "group", "root", "file", "video", "chat",
+ "denylist", "stun", "reload", "restart-daemon",
+ "reset")
+ logging.basicConfig(
+ level=logging.ERROR if quiet else getattr(logging, args.log_level),
+ format="%(asctime)s %(levelname)-8s %(name)s: %(message)s",
+ )
+ return args
+
+
+# Each verb and what runs it. A command line naming none of them starts the
+# daemon, which is daemon.main's to do.
+VERBS = {
+ "init": setup.init,
+ "reset": setup.reset,
+ "status": status.status,
+ "gek-init": groups.gek,
+ "gek": groups.gek,
+ "operator": members.operator,
+ "member": members.member,
+ "group": groups.group,
+ "root": groups.root,
+ "file": content.file,
+ "video": content.video,
+ "chat": content.chat,
+ "denylist": settings.denylist,
+ "stun": settings.stun,
+ "transfers": settings.transfers,
+ "reload": lifecycle.reload,
+ "restart-daemon": lifecycle.restart_daemon,
+ "autostart": lifecycle.autostart,
+ "service": lifecycle.service,
+ "calibrate-argon2": setup.calibrate,
+}
+
+
+def run(args) -> bool:
+ """Run the verb on the command line; False when it names none."""
+ verb = VERBS.get(args.command)
+ if verb is None:
+ return False
+ verb(args)
+ return True