Files
boxmaker/crates/memoryd/src/main.rs
T
kyle 0c8d136c6b memoryd: serve, three sockets and one lock over the files and the index
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
2026-09-25 16:41:44 -07:00

52 lines
1.5 KiB
Rust

//! `memoryd serve --config <path>`.
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::ExitCode;
use std::sync::Arc;
use memoryd::config::Config;
use memoryd::serve;
const USAGE: &str = "usage: memoryd serve --config <path>";
const START_FAILED: &str = "see docs/runbook.md#memoryd-start-failed";
fn main() -> ExitCode {
let args: Vec<OsString> = std::env::args_os().skip(1).collect();
let Some(path) = parse(&args) else {
eprintln!("{USAGE}");
return ExitCode::from(2);
};
let config = match Config::load(&path) {
Ok(config) => config,
Err(e) => {
eprintln!("memoryd: {e}\n{START_FAILED}");
return ExitCode::from(1);
}
};
let log: serve::Log = Arc::new(|line: &str| eprintln!("{line}"));
let running = match serve::start(config, log) {
Ok(running) => running,
Err(e) => {
eprintln!("memoryd: {e}\n{START_FAILED}");
return ExitCode::from(1);
}
};
eprintln!("memoryd: serving");
match running.run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("memoryd: stopped serving: {e}\n{START_FAILED}");
ExitCode::from(1)
}
}
}
/// The config path of `serve --config <path>`, or `None` for any other list.
fn parse(args: &[OsString]) -> Option<PathBuf> {
match args {
[serve, flag, path] if serve == "serve" && flag == "--config" => Some(PathBuf::from(path)),
_ => None,
}
}