omne-cli 0.1.1

CLI for managing omne volumes: init, upgrade, and validate kernel and distro releases
Documentation
//! Volume directory scaffolding.
//!
//! Creates the `.omne/` directory structure, writes the `CLAUDE.md`
//! bootloader, and writes the stamped `MANIFEST.md`. All operations
//! are idempotent — `create_dir_all` does not error on existing dirs.

// Items below are first used when Unit 8a wires this module into
// `init::run`. Until then, only the inline test module uses them.
#![allow(dead_code)]

use std::io;
use std::path::Path;

/// Bootloader content written to `CLAUDE.md` at the volume root.
const BOOTLOADER_CONTENT: &str = "\
# CLAUDE.md

> Bootloader — loads the omne kernel.

Read `.omne/MANIFEST.md` and follow its boot sequence.
";

/// Create the `.omne/` directory structure with `cfg/` and `log/`.
pub fn create_volume_dirs(root: &Path) -> io::Result<()> {
    let omne = root.join(".omne");
    std::fs::create_dir_all(omne.join("cfg"))?;
    std::fs::create_dir_all(omne.join("log"))?;
    Ok(())
}

/// Write the `CLAUDE.md` bootloader to the volume root.
pub fn write_bootloader(root: &Path) -> io::Result<()> {
    std::fs::write(root.join("CLAUDE.md"), BOOTLOADER_CONTENT)
}

/// Write stamped manifest content to `.omne/MANIFEST.md`.
pub fn write_manifest(root: &Path, content: &str) -> io::Result<()> {
    std::fs::write(root.join(".omne").join("MANIFEST.md"), content)
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    // -- create_volume_dirs --

    #[test]
    fn creates_omne_dir() {
        let tmp = TempDir::new().unwrap();
        create_volume_dirs(tmp.path()).unwrap();
        assert!(tmp.path().join(".omne").is_dir());
    }

    #[test]
    fn creates_cfg_dir() {
        let tmp = TempDir::new().unwrap();
        create_volume_dirs(tmp.path()).unwrap();
        assert!(tmp.path().join(".omne").join("cfg").is_dir());
    }

    #[test]
    fn creates_log_dir() {
        let tmp = TempDir::new().unwrap();
        create_volume_dirs(tmp.path()).unwrap();
        assert!(tmp.path().join(".omne").join("log").is_dir());
    }

    #[test]
    fn idempotent() {
        let tmp = TempDir::new().unwrap();
        create_volume_dirs(tmp.path()).unwrap();
        create_volume_dirs(tmp.path()).unwrap();
        assert!(tmp.path().join(".omne").is_dir());
    }

    // -- write_bootloader --

    #[test]
    fn creates_claude_md() {
        let tmp = TempDir::new().unwrap();
        write_bootloader(tmp.path()).unwrap();
        assert!(tmp.path().join("CLAUDE.md").is_file());
    }

    #[test]
    fn bootloader_references_manifest() {
        let tmp = TempDir::new().unwrap();
        write_bootloader(tmp.path()).unwrap();
        let content = std::fs::read_to_string(tmp.path().join("CLAUDE.md")).unwrap();
        assert!(content.contains(".omne/MANIFEST.md"));
    }

    // -- write_manifest --

    #[test]
    fn writes_manifest_file() {
        let tmp = TempDir::new().unwrap();
        std::fs::create_dir_all(tmp.path().join(".omne")).unwrap();
        write_manifest(tmp.path(), "test content").unwrap();
        let path = tmp.path().join(".omne").join("MANIFEST.md");
        assert!(path.is_file());
        assert_eq!(std::fs::read_to_string(path).unwrap(), "test content");
    }
}