use std::path::Path;
use anyhow::{Context, Result};
use sdivi_config::Config;
use sdivi_pipeline::store::{latest_snapshot, read_snapshot_by_id};
use crate::output;
pub fn run(repo_root: &Path, config: &Config, id: Option<&str>, format: &str) -> Result<()> {
let snapshot_dir = repo_root.join(&config.snapshots.dir);
let snapshot = match id {
Some(id) => read_snapshot_by_id(&snapshot_dir, id).with_context(|| {
format!("snapshot '{}' not found in {}", id, snapshot_dir.display())
})?,
None => latest_snapshot(&snapshot_dir)
.with_context(|| format!("failed to read snapshot dir: {}", snapshot_dir.display()))?
.ok_or_else(|| anyhow::anyhow!("no snapshots found in {}", snapshot_dir.display()))?,
};
match format {
"json" => output::json::print_snapshot(&snapshot)?,
_ => output::text::print_snapshot(&snapshot),
}
Ok(())
}