summaryrefslogtreecommitdiff
path: root/src/helpers.rs
diff options
context:
space:
mode:
authorChristopher Warner <cwarner@kernelcode.com>2026-10-10 18:49:01 -0400
committerChristopher Warner <cwarner@kernelcode.com>2026-10-10 18:49:01 -0400
commitbe0d09e2cb91ef391d7455334fc5ed15d6f5649a (patch)
treebc3b8d3c3b79de695761b750789aeb2ddaf8df49 /src/helpers.rs
parentb5e522306f3f4153f633618b8d1e36dc8bbf6371 (diff)
downloadiphone-notes-be0d09e2cb91ef391d7455334fc5ed15d6f5649a.tar.gz
iphone-notes-be0d09e2cb91ef391d7455334fc5ed15d6f5649a.tar.bz2
iphone-notes-be0d09e2cb91ef391d7455334fc5ed15d6f5649a.tar.xz
iphone-notes-be0d09e2cb91ef391d7455334fc5ed15d6f5649a.zip
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 <cursoragent@cursor.com>
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"