use std::{
fs::OpenOptions,
io::{Read, Write},
path::Path,
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub name: String,
pub author: String,
pub standard: String,
pub version: String,
pub license: String,
}
impl Config {
pub fn load(target: &Path) -> anyhow::Result<Self> {
let mut file = OpenOptions::new()
.read(true)
.open(target.join("saja.toml"))?;
let mut buf = String::new();
file.read_to_string(&mut buf)?;
Ok(toml::from_str(&buf)?)
}
pub fn store(&self, target: &Path) -> anyhow::Result<()> {
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(target.join("saja.toml"))?;
let config = toml::to_string_pretty(self)?;
write!(file, "{config}")?;
Ok(())
}
}