This commit is contained in:
Bel LaPointe
2025-11-11 10:39:50 -07:00
parent a899241c28
commit 9242d41a0f
4 changed files with 38 additions and 9 deletions

View File

@@ -4,14 +4,30 @@ use serde_yaml;
use std::io::{BufRead, Read, Write};
fn main() {
for file in Flags::new()
.expect("failed to flags")
.files()
.expect("failed to files")
.files
.iter()
{
file.persist_stage().unwrap();
let flags = Flags::new().expect("failed to flags");
let files = flags.files().expect("failed to files");
assert!(files.files.len() > 0, "no files");
if !flags.dry_run {
for file in files.files.iter() {
file.persist_stage()
.expect("failed to persist staged changes to log file");
file.stage_persisted().expect("failed to stage log files");
}
if let Some(add) = flags.add {
let patch: json_patch::PatchOperation =
json_patch::PatchOperation::Add(json_patch::AddOperation {
path: jsonptr::PointerBuf::parse("/-").expect("cannot create path to /-"),
value: serde_json::json!(add),
});
files.files[0]
.append(Delta::now(patch))
.expect("failed to add");
}
}
for file in files.files.iter() {
println!(
"{} => {}",
file.file,
@@ -80,8 +96,10 @@ struct Files {
impl Files {
fn new(files: &Vec<String>) -> Files {
let mut files = files.clone();
files.sort();
Files {
files: files.into_iter().map(|x| File::new(x)).collect(),
files: files.into_iter().map(|x| File::new(&x)).collect(),
}
}
}
@@ -100,6 +118,10 @@ impl File {
Events::new(&self.file)
}
fn stage_persisted(&self) -> Result<(), String> {
Err("not impl".to_string())
}
fn persist_stage(&self) -> Result<(), String> {
let persisted = self.events()?.snapshot();
let snapshot = serde_json::to_string(&persisted).unwrap();