Skip to main content

mail4agent_messenger_shell/cli/
mod.rs

1//! The client's commands. They used to be eight binaries; they are subcommands of ONE binary,
2//! `m4a-agent <command> ...`, and the old binary names remain as thin wrappers over the same
3//! `run` functions for one transition release (service units keep working; update them to
4//! `m4a-agent <command>` at leisure).
5//!
6//! | `m4a-agent`            | old binary                 |
7//! | ---------------------- | -------------------------- |
8//! | `web-client`           | `m4a-web-client`           |
9//! | `node-client`          | `m4a-node-client`          |
10//! | `grok-listen`          | `m4a-grok-listen`          |
11//! | `claude-channel`       | `m4a-claude-channel`       |
12//! | `inbox`                | `m4a-inbox`                |
13//! | `send`                 | `m4a-send`                 |
14//! | `mail`                 | `m4a`                      |
15//! | `ensure-agent-webhooks`| `m4a-ensure-agent-webhooks`|
16//! | `enroll`               | —                          |
17//! | `wake`                 | — (owner control of wakes) |
18//! | `vault`                | — (status, backup, restore)|
19//! | `element-open`         | — (open Element, logged in)|
20
21#[cfg(feature = "wake-claude")]
22pub mod claude_channel;
23pub mod enroll;
24pub mod session_arg;
25pub mod vault;
26pub mod wake;
27#[cfg(feature = "element-open")]
28pub mod element_open;
29pub mod ensure_agent_webhooks;
30#[cfg(feature = "wake-grok")]
31pub mod grok_listen;
32pub mod inbox;
33pub mod mail;
34#[cfg(feature = "wake-grok")]
35pub mod node_client;
36pub mod send;
37pub mod web_client;
38
39/// The subcommand names, in the order of the table above.
40pub const COMMANDS: &[&str] = &["web-client", "node-client", "grok-listen", "claude-channel", "inbox", "send", "mail", "ensure-agent-webhooks", "enroll", "wake", "vault", "element-open"];
41
42/// Runs `command` with its arguments. `Err` names an unknown command (or one this build lacks).
43pub fn dispatch(command: &str, args: Vec<String>) -> Result<(), String> {
44    match command {
45        "web-client" => web_client::run(args),
46        #[cfg(feature = "wake-grok")]
47        "node-client" => node_client::run(args),
48        #[cfg(feature = "wake-grok")]
49        "grok-listen" => grok_listen::run(args),
50        #[cfg(not(feature = "wake-grok"))]
51        "node-client" | "grok-listen" => return Err("this build was made without feature wake-grok".to_string()),
52        #[cfg(feature = "wake-claude")]
53        "claude-channel" => claude_channel::run(args),
54        "inbox" => inbox::run(args),
55        "send" => send::run(args),
56        "mail" => mail::run(args),
57        "ensure-agent-webhooks" => ensure_agent_webhooks::run(args),
58        "enroll" => enroll::run(args),
59        "wake" => wake::run(args),
60        "vault" => vault::run(args),
61        #[cfg(feature = "element-open")]
62        "element-open" => element_open::run(args),
63        #[cfg(not(feature = "element-open"))]
64        "element-open" => return Err("this build was made without feature element-open".to_string()),
65        other => return Err(format!("unknown command {other:?}; commands: {}", COMMANDS.join(", "))),
66    }
67    Ok(())
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn an_unknown_command_is_named_not_run() {
76        let e = dispatch("nope", vec![]).unwrap_err();
77        assert!(e.contains("nope") && e.contains("web-client") && e.contains("mail"));
78    }
79
80    #[test]
81    fn enroll_is_a_command() {
82        assert!(COMMANDS.contains(&"enroll"));
83    }
84}