obj-cli 1.0.0

Command-line tools (dump, check, stat, backup) for the obj embedded document database.
Documentation
//! Populate a `.obj` file with a tiny, well-known dataset for the
//! CLI cross-platform smoke test (issue #100).
//!
//! Usage:
//!
//! ```sh
//! cargo run --release -p obj-cli --example seed_for_cli -- <path>
//! ```
//!
//! Creates one collection (`smoke_users`) with 8 documents; the
//! smoke harness then runs `obj stat / check / backup` against
//! the resulting file. Exits 0 on success; non-zero with a message
//! on failure.

#![forbid(unsafe_code)]

use std::process::ExitCode;

use obj::{Db, Document};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct SmokeUser {
    email: String,
    handle: String,
}

impl Document for SmokeUser {
    const COLLECTION: &'static str = "smoke_users";
    const VERSION: u32 = 1;
}

fn main() -> ExitCode {
    let mut args = std::env::args_os().skip(1);
    let Some(path) = args.next() else {
        eprintln!("usage: seed_for_cli <path>");
        return ExitCode::from(2);
    };
    let db = match Db::open(&path) {
        Ok(d) => d,
        Err(e) => {
            eprintln!("seed_for_cli: open failed: {e}");
            return ExitCode::from(2);
        }
    };
    for i in 0..8u32 {
        let user = SmokeUser {
            email: format!("user{i}@example.com"),
            handle: format!("u{i}"),
        };
        if let Err(e) = db.insert(user) {
            eprintln!("seed_for_cli: insert failed: {e}");
            return ExitCode::from(2);
        }
    }
    println!("seed_for_cli: 8 docs inserted into smoke_users");
    ExitCode::SUCCESS
}