Enhance CLI arguments with new options, validation, and detailed help messages

This commit is contained in:
2026-03-03 08:28:11 +01:00
parent ccc993976f
commit baca32e57c
3 changed files with 42 additions and 3 deletions

View File

@@ -1,6 +1,27 @@
use regex::Regex;
use std::path::PathBuf;
use once_cell::sync::Lazy;
static PATH_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$").unwrap()
});
pub fn path_exists(s: &str) -> Result<PathBuf, String> {
let p = PathBuf::from(s);
p.exists().then_some(p).ok_or("path does not exist".to_string())
}
pub fn valid_possible_path(s: &str) -> Result<PathBuf, String>
{
let lower = s.to_ascii_lowercase();
if lower == "true" || lower == "false" {
return Err("boolean literal is not allowed".into());
}
if PATH_REGEX.is_match(s) {
return Err("numeric literal is not allowed".into());
}
Ok(PathBuf::from(s))
}