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