35 lines
1 KiB
Rust
35 lines
1 KiB
Rust
use doot_core::{
|
|
Config,
|
|
state::{Snapshot, StateStore},
|
|
};
|
|
use std::path::PathBuf;
|
|
|
|
#[tracing::instrument(skip_all, fields(name = %name))]
|
|
pub fn run(_config_path: Option<PathBuf>, name: String) -> anyhow::Result<()> {
|
|
let config = Config::default();
|
|
config.ensure_dirs()?;
|
|
|
|
let mut state = StateStore::new(&config.state_file);
|
|
|
|
tracing::debug!(
|
|
state_file = %config.state_file.display(),
|
|
snapshot_dir = %config.snapshot_dir.display(),
|
|
"creating snapshot"
|
|
);
|
|
|
|
let state_content =
|
|
std::fs::read_to_string(&config.state_file).unwrap_or_else(|_| "{}".to_string());
|
|
let state_data: doot_core::state::store::State = serde_json::from_str(&state_content)?;
|
|
|
|
Snapshot::create(&name, &state_data, &config.snapshot_dir)?;
|
|
|
|
// Record snapshot in state
|
|
state.add_snapshot(&name);
|
|
state.save()?;
|
|
|
|
println!("snapshot created: {}", name);
|
|
println!(" deployments: {}", state_data.deployments.len());
|
|
println!(" packages: {}", state_data.packages.len());
|
|
|
|
Ok(())
|
|
}
|