Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for extra reminder options #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 32 additions & 1 deletion Sources/RemindersLibrary/CLI.swift
Expand Up @@ -71,11 +71,42 @@ private struct AddReminder: ParsableCommand {
help: "The date the reminder is due")
var dueDate: DateComponents?

@Option(
name: .shortAndLong,
help: "The reminder URL")
var url: URL?

@Option(
name: .shortAndLong,
help: "The reminder location")
var location: String?

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

@Option(
name: .shortAndLong,
help: "The reminder priority")
var priority: Int = 0

func validate() throws {
guard priority >= 0 && priority <= 9 else {
throw ValidationError("'priority' must be between 0 and 9 (inclusive)")
}
}

func run() {
reminders.addReminder(
string: self.reminder.joined(separator: " "),
toListNamed: self.listName,
dueDate: self.dueDate)
dueDate: self.dueDate,
url: self.url,
notes: self.notes,
priority: self.priority,
location: self.location
)
}
}

Expand Down
11 changes: 11 additions & 0 deletions Sources/RemindersLibrary/NaturalLanguage.swift
Expand Up @@ -48,3 +48,14 @@ extension DateComponents: ExpressibleByArgument {
}
}
}

extension URL: ExpressibleByArgument {
public init?(argument: String) {
if let url = URL(string: argument) {
self = url
} else {
return nil
}
}
}

6 changes: 5 additions & 1 deletion Sources/RemindersLibrary/Reminders.swift
Expand Up @@ -163,12 +163,16 @@ public final class Reminders {
semaphore.wait()
}

func addReminder(string: String, toListNamed name: String, dueDate: DateComponents?) {
func addReminder(string: String, toListNamed name: String, dueDate: DateComponents?, url: URL?, notes: String?, priority: Int, location: String?) {
let calendar = self.calendar(withName: name)
let reminder = EKReminder(eventStore: Store)
reminder.calendar = calendar
reminder.title = string
reminder.dueDateComponents = dueDate
reminder.url = url
reminder.notes = notes
reminder.priority = priority
reminder.location = location

do {
try Store.save(reminder, commit: true)
Expand Down
8 changes: 8 additions & 0 deletions Tests/RemindersTests/NaturalLanguageTests.swift
Expand Up @@ -65,4 +65,12 @@ final class NaturalLanguageTests: XCTestCase {
func testIgnoreRandomString() {
XCTAssertNil(DateComponents(argument: "blah tomorrow 9pm"))
}

func testUrl() {
XCTAssertNotNil(URL(string: "https://www.github.com"))
}

func testUrlWithoutDomain() {
XCTAssertNotNil(URL(string: "www.github.com"))
}
}