use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct CommandResultJson {
pub command: String,
pub success: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub profile: Option<serde_json::Value>,
}
impl CommandResultJson {
pub fn success(command: &str, data: serde_json::Value) -> Self {
Self {
command: command.to_string(),
success: true,
profile: Some(data),
}
}
pub fn print(&self) -> Result<(), String> {
println!(
"{}",
serde_json::to_string_pretty(self).map_err(|e| e.to_string())?
);
Ok(())
}
}