Skip to main content

read

Function read 

Source
pub fn read(path: &Path) -> Result<(BTreeMap<String, String>, String), String>
Expand description

Split a record into its front matter (flat key: value lines; list items are skipped) and its body.

This is a reader of one shape, not a YAML parser: a handover’s front matter is flat by contract, and the few facts the mesh needs from it are scalars. Nesting and list items are skipped rather than refused, so a record that carries more than this module understands still publishes.

use majordomus_cli::mesh::handover::read;

let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("record.md");
std::fs::write(
    &path,
    "---\nbranch: feature/x\nchanged_files:\n  - apps/x.rs\n---\n\n# Objective\nship\n",
)
.unwrap();

let (front, body) = read(&path).unwrap();
assert_eq!(front["branch"], "feature/x");
assert!(!front.contains_key("apps/x.rs"), "a list item is not a fact of the front matter");
assert!(body.starts_with("# Objective"));

// a file with no front matter is not a handover record
std::fs::write(&path, "# Objective\nship\n").unwrap();
assert!(read(&path).is_err());