Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ $ reminders show Soon
```
$ reminders edit Soon 0 Some edited text
Updated reminder 'Some edited text'
$ reminders edit Soon 0 --due-date "tomorrow 9am"
Updated reminder 'Some edited text'
$ reminders edit Soon 0 --clear-due-date
Updated reminder 'Some edited text'
$ reminders show Soon
0 Ship reminders-cli
1 Some edited text
Expand Down
21 changes: 18 additions & 3 deletions Sources/RemindersLibrary/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,27 @@ private struct Edit: ParsableCommand {
help: "The notes to set on the reminder, overwriting previous notes")
var notes: String?

@Option(
name: .shortAndLong,
help: "The new date the reminder is due")
var dueDate: DateComponents?

@Flag(help: "Remove the due date from the reminder")
var clearDueDate = false

@Argument(
parsing: .remaining,
help: "The new reminder contents")
var reminder: [String] = []

func validate() throws {
if self.reminder.isEmpty && self.notes == nil {
throw ValidationError("Must specify either new reminder content or new notes")
if self.dueDate != nil && self.clearDueDate {
throw ValidationError("Cannot specify both --due-date and --clear-due-date")
}

if self.reminder.isEmpty && self.notes == nil && self.dueDate == nil && !self.clearDueDate {
throw ValidationError(
"Must specify either new reminder content, new notes, or a due date change")
}
}

Expand All @@ -259,7 +272,9 @@ private struct Edit: ParsableCommand {
itemAtIndex: self.index,
onListNamed: self.listName,
newText: newText.isEmpty ? nil : newText,
newNotes: self.notes
newNotes: self.notes,
newDueDateComponents: self.dueDate,
clearDueDate: self.clearDueDate
)
}
}
Expand Down
26 changes: 25 additions & 1 deletion Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ public final class Reminders {
}
}

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

Expand All @@ -243,6 +250,23 @@ public final class Reminders {
do {
reminder.title = newText ?? reminder.title
reminder.notes = newNotes ?? reminder.notes

if clearDueDate {
reminder.dueDateComponents = nil
for alarm in reminder.alarms ?? [] {
reminder.removeAlarm(alarm)
}
} else if let newDueDateComponents {
reminder.dueDateComponents = newDueDateComponents
for alarm in reminder.alarms ?? [] {
reminder.removeAlarm(alarm)
}

if let dueDate = newDueDateComponents.date, newDueDateComponents.hour != nil {
reminder.addAlarm(EKAlarm(absoluteDate: dueDate))
}
}

try Store.save(reminder, commit: true)
print("Updated reminder '\(reminder.title!)'")
} catch let error {
Expand Down
Loading