Give signald and terminal-garden --help and --version !12

merged merged by cmc on 2026-09-04 14:43 UTC · krz/ambient-companions:fix/cli-help into main

2 files changed, +55 −0

crates/signald/src/main.rs +34
@@ -25,6 +25,7 @@
2525//! signald [--socket <path>] [--db <path>] [--spool <path>]
2626//! [--collector <path>] [--interval-ms <n>] [--retention-days <n>]
2727//! [<repo-path> ...]
28//! signald --help | --version
2829//! ```
2930//! With no repo paths, `$XDG_CONFIG_HOME/signald/repos` (else
3031//! `~/.config/signald/repos`) is read — one path per line, `#` comments
@@ -116,6 +117,24 @@ fn main() {
116117 }
117118}
118119
120const USAGE: &str = "\
121Usage: signald [options] [<repo-path> ...]
122
123 --socket <path> listen here (default $XDG_RUNTIME_DIR/signald.sock,
124 else ~/.local/state/signald/sock)
125 --db <path> sqlite history (default: beside the socket)
126 --spool <path> terminal spool (default: beside the socket)
127 --collector <path> macos-collector binary (default: found on PATH)
128 --interval-ms <n> collector tick (default 2000)
129 --retention-days <n> history retention (default 7)
130 -h, --help print this and exit
131 -V, --version print the version and exit
132
133With no <repo-path>, $XDG_CONFIG_HOME/signald/repos (else
134~/.config/signald/repos) is read, one path per line, # comments ignored.
135Failing that, the working directory is watched.
136";
137
119138fn parse_args() -> Config {
120139 let mut socket: Option<PathBuf> = None;
121140 let mut db: Option<PathBuf> = None;
@@ -138,6 +157,21 @@ fn parse_args() -> Config {
138157 "--retention-days" => {
139158 retention_days = args.next().and_then(|s| s.parse().ok()).unwrap_or(retention_days)
140159 }
160 "--help" | "-h" => {
161 print!("{USAGE}");
162 std::process::exit(0);
163 }
164 "--version" | "-V" => {
165 println!("signald {}", env!("CARGO_PKG_VERSION"));
166 std::process::exit(0);
167 }
168 // Without this an unknown flag becomes a repository path and the
169 // daemon starts anyway, watching a directory that does not exist.
170 _ if arg.starts_with('-') => {
171 eprintln!("signald: unknown option {arg}\n");
172 eprint!("{USAGE}");
173 std::process::exit(2);
174 }
141175 _ => repos.push(PathBuf::from(arg)),
142176 }
143177 }
crates/terminal-garden/src/main.rs +21
@@ -13,6 +13,7 @@
1313//! Usage:
1414//! ```text
1515//! terminal-garden [--socket <path>]
16//! terminal-garden --help | --version
1617//! ```
1718//! Socket defaults to `$XDG_RUNTIME_DIR/signald.sock`, falling back to
1819//! `~/.local/state/signald/sock`.
@@ -76,9 +77,29 @@ fn run(socket: &PathBuf) -> std::io::Result<()> {
7677 Ok(())
7778}
7879
80const USAGE: &str = "\
81Usage: terminal-garden [--socket <path>]
82
83 --socket <path> signald's socket (default $XDG_RUNTIME_DIR/signald.sock,
84 else ~/.local/state/signald/sock)
85 -h, --help print this and exit
86 -V, --version print the version and exit
87";
88
7989fn parse_socket() -> PathBuf {
8090 let mut args = std::env::args().skip(1);
8191 while let Some(arg) = args.next() {
92 match arg.as_str() {
93 "--help" | "-h" => {
94 print!("{USAGE}");
95 std::process::exit(0);
96 }
97 "--version" | "-V" => {
98 println!("terminal-garden {}", env!("CARGO_PKG_VERSION"));
99 std::process::exit(0);
100 }
101 _ => {}
102 }
82103 if arg == "--socket" {
83104 if let Some(path) = args.next() {
84105 return PathBuf::from(path);