Skip to content

Commit

Permalink
♻️ Use new Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
oschrenk committed Jan 19, 2025
1 parent acc6765 commit e1e82d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions Sources/Cli/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum Main {
start: Date,
end: Date,
opts: SharedOptions,
eventSelector: EventSelectorI
postSortingEventSelector: EventSelectorI
) {
Log.setDebug(opts.debug)

Expand All @@ -28,13 +28,18 @@ enum Main {

let service = EventService(repo: EventRepo())

let events = eventSelector.select(events: service.fetch(
let unsortedEvents = service.fetch(
start: start,
end: end,
calendarFilter: calendarFilter,
eventFilter: eventFilter
)).sorted { $0.schedule.end.inMinutes > $1.schedule.end.inMinutes }
)

let selectors = EventSelector.Combined(selectors:
[EventSelector.Sorted(sorting: Sorting()), postSortingEventSelector]
)

let events = selectors.select(events: unsortedEvents)
if opts.templatePath.isEmpty {
events.printAsJson()
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Cli/Next.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ struct Next: ParsableCommand {
let end = FCalendar.current.date(byAdding: .minute, value: within, to: today)!
let eventSelector = EventSelector.Prefix(count: 1)

Main.run(start: start, end: end, opts: opts, eventSelector: eventSelector)
Main.run(start: start, end: end, opts: opts, postSortingEventSelector: eventSelector)
}
}
2 changes: 1 addition & 1 deletion Sources/Cli/Today.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ struct Today: ParsableCommand {
let end = FCalendar.current.date(byAdding: .day, value: 1, to: today)!
let eventSelector = EventSelector.All()

Main.run(start: start, end: end, opts: opts, eventSelector: eventSelector)
Main.run(start: start, end: end, opts: opts, postSortingEventSelector: eventSelector)
}
}

0 comments on commit e1e82d3

Please sign in to comment.