From ede4c0d75914ed8da080d231f653d8a55700f4a8 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 10 Jan 2023 14:18:55 -0800 Subject: [PATCH] Add --notes when adding reminders (#56) ``` reminders add todo some reminder --notes "some notes" ``` It also shows up in `reminders show` Fixes https://github.com/keith/reminders-cli/issues/54 --- Sources/RemindersLibrary/CLI.swift | 6 ++++++ Sources/RemindersLibrary/Reminders.swift | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Sources/RemindersLibrary/CLI.swift b/Sources/RemindersLibrary/CLI.swift index 3574ea0..d0f72ec 100644 --- a/Sources/RemindersLibrary/CLI.swift +++ b/Sources/RemindersLibrary/CLI.swift @@ -90,9 +90,15 @@ private struct Add: ParsableCommand { help: "The priority of the reminder") var priority: Priority = .none + @Option( + name: .shortAndLong, + help: "The notes to add to the reminder") + var notes: String? + func run() { reminders.addReminder( string: self.reminder.joined(separator: " "), + notes: self.notes, toListNamed: self.listName, dueDate: self.dueDate, priority: priority) diff --git a/Sources/RemindersLibrary/Reminders.swift b/Sources/RemindersLibrary/Reminders.swift index 552c2c3..1ceb2d8 100644 --- a/Sources/RemindersLibrary/Reminders.swift +++ b/Sources/RemindersLibrary/Reminders.swift @@ -20,7 +20,8 @@ private func format(_ reminder: EKReminder, at index: Int, listName: String? = n let dateString = formattedDueDate(from: reminder).map { " (\($0))" } ?? "" let priorityString = Priority(reminder.mappedPriority).map { " (priority: \($0))" } ?? "" let listString = listName.map { "\($0): " } ?? "" - return "\(listString)\(index): \(reminder.title ?? "")\(dateString)\(priorityString)" + let notesString = reminder.notes.map { " (\($0))" } ?? "" + return "\(listString)\(index): \(reminder.title ?? "")\(notesString)\(dateString)\(priorityString)" } public enum DisplayOptions: String, Decodable { @@ -251,11 +252,18 @@ public final class Reminders { semaphore.wait() } - func addReminder(string: String, toListNamed name: String, dueDate: DateComponents?, priority: Priority) { + func addReminder( + string: String, + notes: String?, + toListNamed name: String, + dueDate: DateComponents?, + priority: Priority) + { let calendar = self.calendar(withName: name) let reminder = EKReminder(eventStore: Store) reminder.calendar = calendar reminder.title = string + reminder.notes = notes reminder.dueDateComponents = dueDate reminder.priority = Int(priority.value.rawValue)