Skip to main content

mermaid_cli/mermaidd/
cli.rs

1//! The daemon's command line: `--help`, `--version`, and nothing else.
2
3pub const HELP: &str = "\
4mermaidd — Mermaid's background daemon (durable runtime state, remote attach,
5long-running process ownership).
6
7Usage: mermaidd [--version | --help]
8
9With no arguments it runs the daemon in the foreground, serving the control
10socket (a Unix domain socket; an owner-locked named pipe on Windows). On Linux
11it is normally managed via the `mermaid daemon` subcommands (install, start,
12stop, restart, status, logs) rather than invoked directly.
13";
14
15#[derive(Debug, PartialEq, Eq)]
16pub enum CliAction {
17    Run,
18    Version,
19    Help,
20    Unknown(String),
21}
22
23/// Classify `mermaidd`'s invocation. The daemon takes no real arguments, but it
24/// is on `PATH` (and in the distro packages), so it must answer
25/// `--version`/`--help` and reject unknown arguments rather than silently
26/// starting the daemon: a `mermaidd --version` probe would otherwise boot a
27/// foreground daemon and — because startup replaces the control socket — could
28/// knock a running daemon off its socket.
29pub fn classify_args<I: IntoIterator<Item = String>>(args: I) -> CliAction {
30    match args.into_iter().next().as_deref() {
31        None => CliAction::Run,
32        Some("--version" | "-V" | "version") => CliAction::Version,
33        Some("--help" | "-h" | "help") => CliAction::Help,
34        Some(other) => CliAction::Unknown(other.to_string()),
35    }
36}