From be0d09e2cb91ef391d7455334fc5ed15d6f5649a Mon Sep 17 00:00:00 2001 From: Christopher Warner Date: Sat, 10 Oct 2026 18:49:01 -0400 Subject: feat: update existing Apple Notes by title instead of duplicating Add `icloud-note update` that finds a note by title and replaces its content in place so revision requests do not create a second note. Co-authored-by: Cursor --- src/helpers.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/helpers.rs') 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(); @@ -127,6 +144,21 @@ mod tests { assert_eq!(b, "hi"); } + #[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( -- cgit v1.2.3