snapdir_cli/lib.rs
1//! snapdir CLI implementation library.
2//!
3//! Thin clap-derive front end for the `snapdir` orchestrator. `manifest` and
4//! `id` are wired to `snapdir-core`'s in-process walk; the remaining
5//! subcommands are wired to `snapdir-stores`/`snapdir-catalog`. Business
6//! logic lives in the libraries — this crate only parses, dispatches, and
7//! maps errors to exit codes.
8//!
9//! The shipped `snapdir` binary lives in the `snapdir` crate
10//! (`crates/snapdir`), a shim whose `main` calls [`run`]. Two workspace
11//! packages cannot both emit a `snapdir` bin (cargo warns "output filename
12//! collision"), so the bin target moved there and this crate became the
13//! implementation library. `snapdir-cli` versions <= 1.5 keep installing the
14//! old binary.
15//!
16//! **Stability:** [`run`] is a *binary entrypoint*, not a stable library
17//! API. It reads `std::env::args`, prints to stdout/stderr, and returns the
18//! process exit code; no other items are exported and no semver guarantees
19//! are made beyond "the `snapdir` binary keeps behaving as documented".
20
21mod cli;
22// The progress renderer engine, wired into every transfer command and gated by
23// the --no-progress/--quiet/--color flags.
24mod progress;
25
26use std::process::ExitCode;
27
28use clap::Parser;
29
30use crate::cli::Cli;
31
32/// Parses `std::env::args`, dispatches the subcommand, and maps the result
33/// to the process exit code (success → 0, error → 1 after printing the
34/// error chain to stderr).
35///
36/// This is the whole public surface: the `snapdir` binary's `main` is
37/// `fn main() -> ExitCode { snapdir_cli::run() }`.
38#[must_use]
39pub fn run() -> ExitCode {
40 let cli = Cli::parse();
41 match cli.run() {
42 Ok(()) => ExitCode::SUCCESS,
43 Err(err) => {
44 eprintln!("{err:#}");
45 ExitCode::FAILURE
46 }
47 }
48}