obj-cli 1.0.0

Command-line tools (dump, check, stat, backup) for the obj embedded document database.
Documentation
//! `obj backup <src> <dest>` — thin wrapper over `Db::backup_to`.
//!
//! Exit codes: 0 on success, 2 on I/O error (including the case
//! where `dest` already exists — see `Db::backup_to` for the
//! exclusive-open contract).

use std::path::Path;

use obj::Db;

/// Run `obj backup` and return the process exit code.
pub(crate) fn run(src: &Path, dest: &Path) -> i32 {
    let db = match Db::open(src) {
        Ok(db) => db,
        Err(err) => {
            eprintln!("error: failed to open {}: {err}", src.display());
            return 2;
        }
    };
    if let Err(err) = db.backup_to(dest) {
        eprintln!(
            "error: backup {}{} failed: {err}",
            src.display(),
            dest.display(),
        );
        return 2;
    }
    println!("ok: backup {} -> {}", src.display(), dest.display());
    0
}