1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
mod commands;
mod render;
mod utils;
#[cfg(test)]
mod test_utils;
use anyhow::Result;
use caldir_core::Caldir;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "caldir-cli")]
#[command(version)]
#[command(about = "Interact with your caldir events and sync to remote calendars")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
#[command(about = "Connect to a remote calendar provider (e.g., Google Calendar)")]
Connect {
/// Provider name (e.g. "google", "caldav", "icloud", "outlook")
provider: Option<String>,
/// Use hosted OAuth via caldir.org (default: true). Pass --hosted=false to use your own credentials.
#[arg(long, default_value_t = true)]
hosted: bool,
},
#[command(about = "Check if any events have changed (local and remote)")]
Status {
/// Only operate on this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Show events from this date (YYYY-MM-DD, or "start" for all past events)
#[arg(long)]
from: Option<String>,
/// Show events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
/// Show all events (instead of compact view when >5 events)
#[arg(short, long)]
verbose: bool,
},
#[command(about = "Pull changes from remote calendars into local caldir")]
Pull {
/// Only operate on this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Pull events from this date (YYYY-MM-DD, or "start" for all past events)
#[arg(long)]
from: Option<String>,
/// Pull events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
/// Show all events (instead of compact view when >5 events)
#[arg(short, long)]
verbose: bool,
},
#[command(about = "Push changes from local caldir to remote calendars")]
Push {
/// Only operate on this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Push events from this date (YYYY-MM-DD, or "start" for all past events)
#[arg(long)]
from: Option<String>,
/// Push events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
/// Show all events (instead of compact view when >5 events)
#[arg(short, long)]
verbose: bool,
/// Bypass safety checks (e.g. allow deleting all remote events when local is empty)
#[arg(long)]
force: bool,
},
#[command(about = "Sync changes between caldir and remote calendars (push + pull)")]
Sync {
/// Only operate on this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Sync events from this date (YYYY-MM-DD, or "start" for all past events)
#[arg(long)]
from: Option<String>,
/// Sync events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
/// Show all events (instead of compact view when >5 events)
#[arg(short, long)]
verbose: bool,
/// Bypass safety checks (e.g. allow deleting many remote events at once)
#[arg(long)]
force: bool,
},
#[command(about = "List upcoming events across all calendars")]
Events {
/// Only show events from this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Show events from this date (YYYY-MM-DD)
#[arg(long)]
from: Option<String>,
/// Show events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
},
#[command(about = "Show today's events")]
Today {
/// Only show events from this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
},
#[command(about = "Show this week's events (through Sunday)")]
Week {
/// Only show events from this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
},
#[command(about = "Create a new event in caldir")]
New {
/// Event title
title: Option<String>,
/// Start date/time (natural language, e.g. "tomorrow 6pm")
#[arg(short, long)]
start: Option<String>,
/// End date/time (natural language)
#[arg(short, long)]
end: Option<String>,
/// Duration (e.g. "30m", "2 hours")
#[arg(short, long)]
duration: Option<String>,
/// Location
#[arg(short, long)]
location: Option<String>,
/// Calendar slug (defaults to default_calendar from config)
#[arg(short = 'C', long)]
calendar: Option<String>,
/// Reminder(s) before the event (e.g. "10m", "1h", "2 days"). Can be repeated.
#[arg(short, long, conflicts_with = "no_reminders")]
reminder: Vec<String>,
/// Do not add any reminders (overrides default_reminders config)
#[arg(long)]
no_reminders: bool,
},
#[command(about = "Discard unpushed local changes (restore to remote state)")]
Discard {
/// Only operate on this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Discard events from this date (YYYY-MM-DD, or "start" for all past events)
#[arg(long)]
from: Option<String>,
/// Discard events until this date (YYYY-MM-DD)
#[arg(long)]
to: Option<String>,
/// Show all events (instead of compact view when >5 events)
#[arg(short, long)]
verbose: bool,
/// Skip confirmation prompt
#[arg(long)]
force: bool,
},
#[command(about = "List pending invites across calendars")]
Invites {
/// Only show invites from this calendar (by slug)
#[arg(short, long)]
calendar: Option<String>,
/// Include already-responded invites (not just pending)
#[arg(short, long)]
all: bool,
},
#[command(about = "Respond to a calendar invite")]
Rsvp {
/// Path to the .ics file (omit for interactive mode)
path: Option<String>,
/// Response: accept, decline, maybe
response: Option<String>,
},
#[command(about = "Show configuration paths and calendar info")]
Config,
#[command(about = "Check your caldir for bad data (e.g. duplicate files)")]
Doctor,
#[command(about = "Update caldir and installed providers to the latest version")]
Update,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
// `update` doesn't touch the caldir, so dispatch it before loading anything.
if let Commands::Update = cli.command {
return commands::update::run().await;
}
let mut caldir = Caldir::load()?;
match cli.command {
Commands::Connect { provider, hosted } => {
commands::connect::run(&mut caldir, provider, hosted).await
}
Commands::Status {
calendar,
from,
to,
verbose,
} => commands::status::run(&caldir, calendar, from, to, verbose).await,
Commands::Pull {
calendar,
from,
to,
verbose,
} => commands::pull::run(&caldir, calendar.into_iter().collect(), from, to, verbose).await,
Commands::Push {
calendar,
from,
to,
verbose,
force,
} => commands::push::run(&caldir, calendar, from, to, verbose, force).await,
Commands::Sync {
calendar,
from,
to,
verbose,
force,
} => commands::sync::run(&caldir, calendar, from, to, verbose, force).await,
Commands::Events { calendar, from, to } => {
commands::events::run(&caldir, calendar, from, to)
}
Commands::Today { calendar } => commands::today::run(&caldir, calendar),
Commands::Week { calendar } => commands::week::run(&caldir, calendar),
Commands::New {
title,
start,
end,
duration,
location,
calendar,
reminder,
no_reminders,
} => commands::new::run(
&caldir,
title,
start,
end,
duration,
location,
calendar,
reminder,
no_reminders,
),
Commands::Discard {
calendar,
from,
to,
verbose,
force,
} => commands::discard::run(&caldir, calendar, from, to, verbose, force).await,
Commands::Invites { calendar, all } => commands::invites::run(&caldir, calendar, all),
Commands::Rsvp { path, response } => commands::rsvp::run(&caldir, path, response),
Commands::Config => commands::config::run(&caldir),
Commands::Doctor => commands::doctor::run(&caldir),
Commands::Update => unreachable!("handled above"),
}
}