systemprompt_cli/commands/admin/config/
profile_io.rs1use std::path::Path;
12
13use anyhow::{Context, Result};
14use systemprompt_models::Profile;
15
16pub(super) fn load_profile(path: &str) -> Result<Profile> {
17 let content = std::fs::read_to_string(path)
18 .with_context(|| format!("Failed to read profile: {}", path))?;
19 serde_yaml::from_str(&content).with_context(|| format!("Failed to parse profile: {}", path))
20}
21
22pub(super) fn save_profile(profile: &Profile, path: &str) -> Result<()> {
23 profile
24 .validate()
25 .context("profile is invalid after edit; refusing to write")?;
26 let content = serde_yaml::to_string(profile).context("Failed to serialize profile")?;
27 std::fs::write(path, content).with_context(|| format!("Failed to write profile: {}", path))?;
28 Ok(())
29}
30
31pub(super) fn profile_dir(path: &str) -> &Path {
32 Path::new(path).parent().unwrap_or_else(|| Path::new("."))
33}