Skip to content

Commit 570306f

Browse files
committed
✨ Filter calendars
1 parent 897d7eb commit 570306f

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

Sources/Cli/Calendars.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,51 @@ struct Calendars: ParsableCommand {
2020
valueName: "f"
2121
)) var format: CalendarFormat = .json
2222

23+
@Option(help: ArgumentHelp(
24+
"Select calendars <v>. A comma separated list of calendar UUIDs",
25+
valueName: "v"
26+
)) var selectCalendars: [String] = []
27+
28+
@Option(help: ArgumentHelp(
29+
"Ignore calendars <v>. A comma separated list of calendar UUIDs",
30+
valueName: "v"
31+
)) var ignoreCalendars: [String] = []
32+
33+
@Option(help: ArgumentHelp(
34+
"Select calendar sources <s>. A comma separated list of calendar sources",
35+
valueName: "s"
36+
)) var selectCalendarSources: [String] = []
37+
38+
@Option(help: ArgumentHelp(
39+
"Ignore calendar sources <s>. A comma separated list of calendar sources",
40+
valueName: "s"
41+
)) var ignoreCalendarSources: [String] = []
42+
43+
@Option(help: ArgumentHelp(
44+
"Select calendar types <v>. A comma separated list of calendar types. " +
45+
"Available: [local|caldav|exchange|subscription|birthday]",
46+
valueName: "v"
47+
)) var selectCalendarTypes: [EKCalendarType] = []
48+
49+
@Option(help: ArgumentHelp(
50+
"Ignore calendar types <v>. A comma separated list of calendar types. " +
51+
"Available: [local|caldav|exchange|subscription|birthday]",
52+
valueName: "v"
53+
)) var ignoreCalendarTypes: [EKCalendarType] = []
54+
2355
mutating func run() {
2456
Log.setDebug(debug)
2557

26-
let calendars = EventStore().calendars()
58+
let calendarFilter = CalendarFilter.build(
59+
selectCalendars: selectCalendars,
60+
ignoreCalendars: ignoreCalendars,
61+
selectCalendarSources: selectCalendarSources,
62+
ignoreCalendarSources: ignoreCalendarSources,
63+
selectCalendarTypes: selectCalendarTypes,
64+
ignoreCalendarTypes: ignoreCalendarTypes
65+
)
66+
67+
let calendars = EventStore().calendars(filter: calendarFilter)
2768

2869
switch format {
2970
case .json:

Sources/EventStore.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ struct EventStore {
3131
return eventStore.calendars(for: EKEntityType.event)
3232
}
3333

34-
func calendars() -> [PlanCalendar] {
35-
return fetchCalendars().map { calendar in
36-
calendar.asCal()
37-
}
34+
/// Returns a list of calendars
35+
///
36+
/// - Parameters:
37+
/// - filter: A filter to select certain calendars
38+
func calendars(filter: (PlanCalendar) -> Bool) -> [PlanCalendar] {
39+
return CalendarSelector.build(
40+
calendars: fetchCalendars(),
41+
filter: filter
42+
).map { $0.asCal() }
3843
}
3944

4045
/// Returns a list of events

0 commit comments

Comments
 (0)