Add path validation utility and integrate with CLI

This commit is contained in:
2026-03-02 20:37:31 +01:00
parent e8cf10eee3
commit 08aa198b00
6 changed files with 20 additions and 10 deletions

View File

@@ -1,13 +1,18 @@
use clap::Parser;
use std::{
ffi::OsStr,
path::PathBuf
};
use clap::{
Parser,
ValueHint::FilePath,
};
use crate::util::fs;
#[derive(Parser, Debug)]
#[command(name = "pmp", about, version)]
pub struct Args {
#[arg(long)]
#[arg(long, value_hint = FilePath, value_parser = fs::path_exists)]
php: Option<PathBuf>,
#[arg(long, short = 'd', hide = true)]
@@ -15,8 +20,8 @@ pub struct Args {
#[arg(long, short = 'v')]
verbose: bool,
#[arg(default_value_os = OsStr::new("."))]
files: Vec<PathBuf>,
#[arg(default_value_os = OsStr::new("."), value_hint = FilePath, value_parser = fs::path_exists)]
directory: Option<PathBuf>,
#[arg(last = true)]
passthrough: Vec<String>,
}

View File

@@ -1 +1,2 @@
pub mod cli;
pub mod util;

View File

@@ -1,8 +1,8 @@
use pmp::{ cli::Args };
fn main()
fn main()
{
let args = Args::parse();
println!("{:?}", args);
println!("{:#?}", args);
}

6
src/util/fs.rs Normal file
View File

@@ -0,0 +1,6 @@
use std::path::PathBuf;
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())
}

1
src/util/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod fs;