use std::fs;
use std::path::{Path, PathBuf};
use vespertide_config::VespertideConfig;
pub(crate) struct CwdGuard {
original: PathBuf,
}
impl CwdGuard {
pub(crate) fn new(dir: impl AsRef<Path>) -> Self {
let original = std::env::current_dir().unwrap();
std::env::set_current_dir(dir.as_ref()).unwrap();
Self { original }
}
}
impl Drop for CwdGuard {
fn drop(&mut self) {
let _ = std::env::set_current_dir(&self.original);
}
}
pub(crate) fn write_default_config(at: impl AsRef<Path>) {
let cfg = VespertideConfig::default();
let text = serde_json::to_string_pretty(&cfg).unwrap();
fs::write(at.as_ref(), text).unwrap();
}