summaryrefslogtreecommitdiff
path: root/src/helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers.rs')
-rw-r--r--src/helpers.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/helpers.rs b/src/helpers.rs
index c6a8163..3ea7e37 100644
--- a/src/helpers.rs
+++ b/src/helpers.rs
@@ -51,6 +51,23 @@ pub fn require_create_content(title: &str, body: &str) -> Result<(String, String
Ok((title, body))
}
+/// Update requires a title to locate the existing note.
+pub fn require_update_content(title: &str, body: &str) -> Result<(String, String), String> {
+ let title = title.trim().to_string();
+ let body = body.trim_end().to_string();
+ if title.is_empty() {
+ return Err(
+ "Provide --title (existing note title to update)".to_string(),
+ );
+ }
+ Ok((title, body))
+}
+
+/// Case-insensitive title equality for matching Notes.app titles.
+pub fn titles_match(a: &str, b: &str) -> bool {
+ a.trim().eq_ignore_ascii_case(b.trim())
+}
+
/// Conventional Commits 1.0.0 subject line (no regex crate).
pub fn is_conventional_commit_subject(subject: &str) -> bool {
let line = subject.trim();
@@ -128,6 +145,21 @@ mod tests {
}
#[test]
+ fn update_content_requires_title() {
+ assert!(require_update_content("", "body").is_err());
+ let (t, b) = require_update_content(" Hello ", "body\n").unwrap();
+ assert_eq!(t, "Hello");
+ assert_eq!(b, "body");
+ }
+
+ #[test]
+ fn titles_match_case_insensitive() {
+ assert!(titles_match("Hello", "hello"));
+ assert!(titles_match(" Foo ", "foo"));
+ assert!(!titles_match("a", "b"));
+ }
+
+ #[test]
fn conventional_subjects() {
assert!(is_conventional_commit_subject(
"feat: add icloud.com/notes helper and agent skill"