From bbc2a7a9447804d31d949c1d8d1143336c5dad79 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 17 Aug 2024 14:47:57 +0000
Subject: [PATCH 1/4] feat: Support key without value in custom fields parser
Signed-off-by: Awiteb
---
src/clap_parsers.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/clap_parsers.rs b/src/clap_parsers.rs
index 05a423e..7666505 100644
--- a/src/clap_parsers.rs
+++ b/src/clap_parsers.rs
@@ -19,12 +19,14 @@ use crate::{LprsError, LprsResult};
/// Parse the key & value arguments.
/// ## Errors
/// - If the argument value syntax not `key=value`
-pub fn kv_parser(value: &str) -> LprsResult<(String, String)> {
+pub fn kv_parser(value: &str) -> LprsResult<(String, Option)> {
if let Some((key, value)) = value.split_once('=') {
- Ok((key.trim().to_owned(), value.trim().to_owned()))
- } else {
+ Ok((key.trim().to_owned(), Some(value.trim().to_owned())))
+ } else if value.trim().is_empty() {
Err(LprsError::ArgParse(
- "There is no value, the syntax is `KEY=VALUE`".to_owned(),
+ "Invalid key, the syntax is `KEY(=VALUE)?`".to_owned(),
))
+ } else {
+ Ok((value.trim().to_owned(), None))
}
}
--
2.45.2
From 2f0531fbc997f38f910dc0cd5b6273d3d96ce52e Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 17 Aug 2024 14:50:38 +0000
Subject: [PATCH 2/4] chore: Util to ask the user for the value of a key
without value
Signed-off-by: Awiteb
---
src/utils.rs | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/utils.rs b/src/utils.rs
index eb5ed46..74eccba 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -181,7 +181,7 @@ pub fn lprs_version() -> LprsResult