summaryrefslogtreecommitdiff
path: root/src/main.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/main.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/main.rs')
-rw-r--r--src/main.rs55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index ccd21e2..ca893b5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,7 @@ use clap::{Parser, Subcommand};
use icloud_note::browser;
use icloud_note::config::{dry_run, Paths};
-use icloud_note::helpers::{format_note_text, require_create_content};
+use icloud_note::helpers::{format_note_text, require_create_content, require_update_content};
#[derive(Parser, Debug)]
#[command(
@@ -29,7 +29,7 @@ enum Command {
Status,
/// One-time Apple ID sign-in (visible browser)
Login,
- /// Headless create a note
+ /// Headless create a new note
Create {
/// Note title (or positional)
#[arg(long)]
@@ -44,6 +44,24 @@ enum Command {
#[arg(value_name = "TITLE")]
positional_title: Option<String>,
},
+ /// Headless update an existing note (by title) — never creates
+ Update {
+ /// Existing note title to find (required)
+ #[arg(long)]
+ title: Option<String>,
+ /// Optional distinct title to search for (defaults to --title)
+ #[arg(long = "match-title")]
+ match_title: Option<String>,
+ /// Replacement body text
+ #[arg(long)]
+ body: Option<String>,
+ /// Read body from file (`-` = stdin)
+ #[arg(long = "body-file")]
+ body_file: Option<PathBuf>,
+ /// Positional title fallback
+ #[arg(value_name = "TITLE")]
+ positional_title: Option<String>,
+ },
}
#[tokio::main]
@@ -115,6 +133,35 @@ async fn run() -> Result<()> {
}
browser::cmd_create(&paths, &title, &body).await
}
+ Command::Update {
+ title,
+ match_title,
+ body,
+ body_file,
+ positional_title,
+ } => {
+ let title = title.or(positional_title).unwrap_or_default();
+ let body_raw = read_body(body, body_file)?;
+ let (title, body) = require_update_content(&title, &body_raw)
+ .map_err(|e| anyhow::anyhow!(e))?;
+ let match_title = match_title
+ .as_deref()
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ .unwrap_or(title.as_str())
+ .to_string();
+ if dry_run() {
+ let text = format_note_text(&title, &body);
+ println!(
+ "dry-run: would update note match={} title={} chars={}",
+ serde_json::to_string(&match_title)?,
+ serde_json::to_string(&title)?,
+ text.len()
+ );
+ return Ok(());
+ }
+ browser::cmd_update(&paths, &match_title, &title, &body).await
+ }
}
}
@@ -151,10 +198,12 @@ fn print_help(paths: &Paths) {
icloud-note status
icloud-note login # only command that opens a visible browser
icloud-note create --title TITLE [--body TEXT | --body-file PATH|-]
+ icloud-note update --title TITLE [--body TEXT | --body-file PATH|-]
+ # updates existing note by title; never creates
Config: {}
Profile: {}
-create/status always run headless (no window).
+create/update/status always run headless (no window).
",
paths.config_dir.display(),
paths.profile_dir.display()