Skip to content

Commit 91c1d93

Browse files
authored
Small style fixes for notes (#66)
1 parent 9765de1 commit 91c1d93

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

Sources/RemindersLibrary/CLI.swift

+10-4
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,21 @@ private struct Edit: ParsableCommand {
209209
help: "The index or id of the reminder to delete, see 'show' for indexes")
210210
var index: String
211211

212+
@Option(
213+
name: .shortAndLong,
214+
help: "The notes to set on the reminder, overwriting previous notes")
215+
var notes: String?
216+
212217
@Argument(
213218
parsing: .remaining,
214219
help: "The new reminder contents")
215220
var reminder: [String] = []
216221

217-
@Option(
218-
name: .shortAndLong,
219-
help: "The new notes")
220-
var notes: String?
222+
func validate() throws {
223+
if self.reminder.isEmpty && self.notes == nil {
224+
throw ValidationError("Must specify either new reminder content or new notes")
225+
}
226+
}
221227

222228
func run() {
223229
let newText = self.reminder.joined(separator: " ")

Sources/RemindersLibrary/Reminders.swift

+2-11
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,9 @@ public final class Reminders {
222222
exit(1)
223223
}
224224

225-
if newText == nil && newNotes == nil {
226-
print("Nothing to update")
227-
exit(1)
228-
}
229-
230225
do {
231-
if let newText = newText {
232-
reminder.title = newText
233-
}
234-
if let newNotes = newNotes {
235-
reminder.notes = newNotes
236-
}
226+
reminder.title = newText ?? reminder.title
227+
reminder.notes = newNotes ?? reminder.notes
237228
try Store.save(reminder, commit: true)
238229
print("Updated reminder '\(reminder.title!)'")
239230
} catch let error {

0 commit comments

Comments
 (0)