Skip to content

Commit

Permalink
Add --notes when adding reminders (#56)
Browse files Browse the repository at this point in the history
```
reminders add todo some reminder --notes "some notes"
```

It also shows up in `reminders show`

Fixes #54
  • Loading branch information
keith authored Jan 10, 2023
1 parent 75ecc1b commit ede4c0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Sources/RemindersLibrary/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "<unknown>")\(dateString)\(priorityString)"
let notesString = reminder.notes.map { " (\($0))" } ?? ""
return "\(listString)\(index): \(reminder.title ?? "<unknown>")\(notesString)\(dateString)\(priorityString)"
}

public enum DisplayOptions: String, Decodable {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ede4c0d

Please sign in to comment.