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
17#[cfg(feature = "wake-claude")]
18pub mod claude_channel;
19pub mod ensure_agent_webhooks;
20#[cfg(feature = "wake-grok")]
21pub mod grok_listen;
22pub mod inbox;
23pub mod mail;
24#[cfg(feature = "wake-grok")]
25pub mod node_client;
26pub mod send;
27pub mod web_client;
28
29/// The subcommand names, in the order of the table above.
30pub const COMMANDS: &[&str] = &["web-client", "node-client", "grok-listen", "claude-channel", "inbox", "send", "mail", "ensure-agent-webhooks"];
31
32/// Runs `command` with its arguments. `Err` names an unknown command (or one this build lacks).
33pub fn dispatch(command: &str, args: Vec<String>) -> Result<(), String> {
34    match command {
35        "web-client" => web_client::run(args),
36        #[cfg(feature = "wake-grok")]
37        "node-client" => node_client::run(args),
38        #[cfg(feature = "wake-grok")]
39        "grok-listen" => grok_listen::run(args),
40        #[cfg(not(feature = "wake-grok"))]
41        "node-client" | "grok-listen" => return Err("this build was made without feature wake-grok".to_string()),
42        #[cfg(feature = "wake-claude")]
43        "claude-channel" => claude_channel::run(args),
44        "inbox" => inbox::run(args),
45        "send" => send::run(args),
46        "mail" => mail::run(args),
47        "ensure-agent-webhooks" => ensure_agent_webhooks::run(args),
48        other => return Err(format!("unknown command {other:?}; commands: {}", COMMANDS.join(", "))),
49    }
50    Ok(())
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn an_unknown_command_is_named_not_run() {
59        let e = dispatch("nope", vec![]).unwrap_err();
60        assert!(e.contains("nope") && e.contains("web-client") && e.contains("mail"));
61    }
62}