use std::path::PathBuf;
use crate::VisualizationError;
pub(crate) fn default_output_path() -> Result<PathBuf, VisualizationError> {
if let Some(home) = dirs::home_dir() {
return Ok(home.join("graph_visualization.html"));
}
for var in ["HOME", "USERPROFILE"] {
if let Ok(v) = std::env::var(var)
&& !v.is_empty()
{
return Ok(PathBuf::from(v).join("graph_visualization.html"));
}
}
Err(VisualizationError::NoHomeDir)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_a_path_or_error() {
if let Ok(path) = default_output_path() {
assert_eq!(
path.file_name().and_then(|s| s.to_str()),
Some("graph_visualization.html")
);
}
}
}