Skip to content

Commit

Permalink
Small renames (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Aug 23, 2023
1 parent 0b12c65 commit dace66f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Sources/RemindersLibrary/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private struct Complete: ParsableCommand {
var index: String

func run() {
reminders.complete(itemAtIndex: self.index, onListNamed: self.listName, isCompleted:true)
reminders.setComplete(true, itemAtIndex: self.index, onListNamed: self.listName)
}
}

Expand All @@ -168,7 +168,7 @@ private struct Uncomplete: ParsableCommand {
var index: String

func run() {
reminders.complete(itemAtIndex: self.index, onListNamed: self.listName, isCompleted:false)
reminders.setComplete(false, itemAtIndex: self.index, onListNamed: self.listName)
}
}

Expand Down
16 changes: 6 additions & 10 deletions Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,23 @@ public final class Reminders {
semaphore.wait()
}

func complete(itemAtIndex index: String, onListNamed name: String, isCompleted :Bool) {
func setComplete(_ complete: Bool, itemAtIndex index: String, onListNamed name: String) {
let calendar = self.calendar(withName: name)
let semaphore = DispatchSemaphore(value: 0)
var displayOptions = DisplayOptions.incomplete
var message = "Completed"

if isCompleted == false {
displayOptions = DisplayOptions.complete
message = "Uncompleted"
}
let displayOptions = complete ? DisplayOptions.incomplete : .complete
let action = complete ? "Completed" : "Uncompleted"

self.reminders(on: [calendar], displayOptions: displayOptions) { reminders in
print(reminders.map { $0.title! })
guard let reminder = self.getReminder(from: reminders, at: index) else {
print("No reminder at index \(index) on \(name)")
exit(1)
}

do {
reminder.isCompleted = isCompleted
reminder.isCompleted = complete
try Store.save(reminder, commit: true)
print("\(message) '\(reminder.title!)'")
print("\(action) '\(reminder.title!)'")
} catch let error {
print("Failed to save reminder with error: \(error)")
exit(1)
Expand Down

0 comments on commit dace66f

Please sign in to comment.