refact: overhaul arg parsing

This commit is contained in:
steven-omaha
2023-05-23 17:28:51 +02:00
parent 79c9e51e8c
commit a4639a1c3a
13 changed files with 222 additions and 258 deletions
+14
View File
@@ -6,6 +6,7 @@ use std::path::PathBuf;
use std::{env, path::Path};
use anyhow::{Context, Result};
use path_absolutize::Absolutize;
const CONFIG_FILE_NAME: &str = "pacdef.yaml";
const CONFIG_FILE_NAME_OLD: &str = "pacdef.conf";
@@ -120,6 +121,19 @@ where
relative_path
}
/// For each file argument, return the absolute path to the file.
pub(crate) fn get_absolutized_file_paths(arg_match: &[String]) -> Result<Vec<PathBuf>> {
Ok(arg_match
.iter()
.map(PathBuf::from)
.map(|path| {
path.absolutize()
.expect("absolute path should exist")
.into_owned()
})
.collect())
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;