41 lines
998 B
Rust
41 lines
998 B
Rust
use std::path::{Path, PathBuf};
|
|
use std::sync::LazyLock;
|
|
|
|
use crate::cli::CONFIG;
|
|
|
|
use anyhow::{self, Context};
|
|
|
|
/// Generates a file path if one not provided.
|
|
/// root_path for fallback name.
|
|
pub fn get_path<P>(path: &Option<P>, root_path: &P, extension: &str) -> anyhow::Result<PathBuf>
|
|
where
|
|
P: AsRef<Path>,
|
|
{
|
|
if let Some(f) = path {
|
|
return Ok(f.as_ref().to_path_buf());
|
|
}
|
|
|
|
Ok(PathBuf::from(format!(
|
|
"{}.{}",
|
|
root_path
|
|
.as_ref()
|
|
.to_str()
|
|
.context("source_name path was not UTF-8 valid.")?,
|
|
extension
|
|
))
|
|
.as_path()
|
|
.to_owned())
|
|
}
|
|
|
|
pub static MAP_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
|
get_path(&CONFIG.map, &CONFIG.input, "map")
|
|
.context("Failed to generate map path.")
|
|
.unwrap()
|
|
});
|
|
|
|
pub static OUTPUT_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
|
get_path(&CONFIG.output, &CONFIG.input, "iso")
|
|
.context("Failed to generate output path.")
|
|
.unwrap()
|
|
});
|