Skip to content

Commit

Permalink
Add --notes option to edit command (#62)
Browse files Browse the repository at this point in the history
- Makes it possible to edit the notes of an existing reminder.
- Edit the title, or notes, or both at the same time (basically behaves
as can reasonably be expected imo).
- I thought about making it possible to append to the existing notes but
replacing it is more flexible and consistent with the way the title can
already be edited.

This is a small part of what was requested on #59.
  • Loading branch information
ngsilverman authored Aug 23, 2023
1 parent dace66f commit 9765de1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
16 changes: 13 additions & 3 deletions Sources/RemindersLibrary/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,21 @@ private struct Edit: ParsableCommand {
@Argument(
parsing: .remaining,
help: "The new reminder contents")
var reminder: [String]
var reminder: [String] = []

@Option(
name: .shortAndLong,
help: "The new notes")
var notes: String?

func run() {
reminders.edit(itemAtIndex: self.index, onListNamed: self.listName,
newText: self.reminder.joined(separator: " "))
let newText = self.reminder.joined(separator: " ")
reminders.edit(
itemAtIndex: self.index,
onListNamed: self.listName,
newText: newText.isEmpty ? nil : newText,
newNotes: self.notes
)
}
}

Expand Down
14 changes: 12 additions & 2 deletions Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public final class Reminders {
}
}

func edit(itemAtIndex index: String, onListNamed name: String, newText: String) {
func edit(itemAtIndex index: String, onListNamed name: String, newText: String?, newNotes: String?) {
let calendar = self.calendar(withName: name)
let semaphore = DispatchSemaphore(value: 0)

Expand All @@ -222,8 +222,18 @@ public final class Reminders {
exit(1)
}

if newText == nil && newNotes == nil {
print("Nothing to update")
exit(1)
}

do {
reminder.title = newText
if let newText = newText {
reminder.title = newText
}
if let newNotes = newNotes {
reminder.notes = newNotes
}
try Store.save(reminder, commit: true)
print("Updated reminder '\(reminder.title!)'")
} catch let error {
Expand Down

0 comments on commit 9765de1

Please sign in to comment.