From 3f16475223504ea6a11ea974b74d13dc92aeeb31 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Thu, 11 Jul 2024 16:05:51 +0200 Subject: [PATCH 1/2] feat: error when `recipe-dir` is not a directory --- src/opt.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/opt.rs b/src/opt.rs index 94eb6e00..0f90d47d 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -251,7 +251,7 @@ pub struct BuildOpts { pub recipe: Vec, /// The directory that contains recipes. - #[arg(long)] + #[arg(long, value_parser = is_dir)] pub recipe_dir: Option, /// Build recipes up to the specified package. @@ -332,6 +332,17 @@ pub struct BuildOpts { pub skip_existing: SkipExisting, } +fn is_dir(dir: &str) -> Result { + let path = PathBuf::from(dir); + if path.is_dir() { + Ok(path) + } else { + Err(format!( + "Path '{dir}' needs to exist on disk and be a directory.", + )) + } +} + /// Test options. #[derive(Parser)] pub struct TestOpts { From 50e14e40b52adb24c59b986c4cc77e251b3d5a2d Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Thu, 11 Jul 2024 16:09:38 +0200 Subject: [PATCH 2/2] Remove punctuation --- src/opt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opt.rs b/src/opt.rs index 0f90d47d..4cb5faaa 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -338,7 +338,7 @@ fn is_dir(dir: &str) -> Result { Ok(path) } else { Err(format!( - "Path '{dir}' needs to exist on disk and be a directory.", + "Path '{dir}' needs to exist on disk and be a directory", )) } }