Skip to main content

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// Pure `snapdir diff` comparison logic (manifest map-diff + porcelain/JSON
23// rendering); the store reads live in `cli`.
24mod diff;
25// The progress renderer engine, wired into every transfer command and gated by
26// the --no-progress/--quiet/--color flags.
27mod progress;
28
29use std::process::ExitCode;
30
31use clap::Parser;
32
33use crate::cli::Cli;
34
35/// Parses `std::env::args`, dispatches the subcommand, and maps the result
36/// to the process exit code (success → 0, error → 1 after printing the
37/// error chain to stderr).
38///
39/// This is the whole public surface: the `snapdir` binary's `main` is
40/// `fn main() -> ExitCode { snapdir_cli::run() }`.
41#[must_use]
42pub fn run() -> ExitCode {
43    let cli = Cli::parse();
44    match cli.run() {
45        Ok(()) => ExitCode::SUCCESS,
46        Err(err) => {
47            eprintln!("{err:#}");
48            ExitCode::FAILURE
49        }
50    }
51}