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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
use clap::{CommandFactory, Parser, Subcommand};
use zoom_cli::config::Config;
use zoom_cli::output::{OutputConfig, OutputFormat, exit_codes};
use zoom_cli::{api, commands};
#[derive(Parser)]
#[command(
name = "zoom",
version,
about = "CLI for the Zoom API. Run 'zoom schema' for machine-readable command reference.",
arg_required_else_help = true
)]
struct Cli {
/// Config profile to use [env: ZOOM_PROFILE]
#[arg(long, env = "ZOOM_PROFILE", global = true)]
profile: Option<String>,
/// Output format: auto (default), text, json [env: ZOOM_OUTPUT]
#[arg(long = "output", short = 'o', global = true, default_value = "auto", env = "ZOOM_OUTPUT", value_parser = ["auto", "text", "json"])]
output: String,
/// Output as JSON (alias for --output=json)
#[arg(long, global = true, hide = true)]
json: bool,
/// Suppress non-data output (counts, confirmations)
#[arg(long, global = true)]
quiet: bool,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Manage meetings
#[command(subcommand, arg_required_else_help = true)]
Meetings(MeetingsCommand),
/// Manage recordings
#[command(subcommand, arg_required_else_help = true)]
Recordings(RecordingsCommand),
/// Manage users
#[command(subcommand, arg_required_else_help = true)]
Users(UsersCommand),
/// Meeting and usage reports
#[command(subcommand, arg_required_else_help = true)]
Reports(ReportsCommand),
/// Manage webinars
#[command(subcommand, arg_required_else_help = true)]
Webinars(WebinarsCommand),
/// Manage configuration
#[command(subcommand, arg_required_else_help = true)]
Config(ConfigCommand),
/// Set up credentials interactively (or print JSON schema for agents)
Init {
/// Profile name to create or update (default: "default")
#[arg(long)]
profile: Option<String>,
},
/// Print machine-readable clispec v0.3 schema
Schema,
/// Generate shell completions
Completions {
/// Shell to generate completions for
shell: clap_complete::Shell,
},
}
#[derive(Subcommand)]
enum ConfigCommand {
/// Show current configuration: profiles, active profile, and env overrides
Show,
/// Delete a profile from the config file
Delete {
/// Profile name to delete
profile: String,
/// Skip confirmation prompt
#[arg(long)]
force: bool,
},
}
#[derive(Subcommand)]
enum MeetingsCommand {
/// List meetings for a user
List {
#[arg(long, default_value = "me")]
user: String,
#[arg(long)]
r#type: Option<String>,
/// Maximum number of results to return
#[arg(long)]
limit: Option<u32>,
/// Number of results to skip
#[arg(long)]
offset: Option<u32>,
/// Comma-separated fields to include in output
#[arg(long, value_delimiter = ',')]
fields: Option<Vec<String>>,
},
/// Get a meeting by ID
Get { id: u64 },
/// Create a meeting
Create {
#[arg(long)]
topic: String,
#[arg(long)]
duration: Option<u32>,
#[arg(long)]
start: Option<String>,
#[arg(long)]
password: Option<String>,
},
/// Update a meeting
Update {
id: u64,
#[arg(long)]
topic: Option<String>,
#[arg(long)]
duration: Option<u32>,
#[arg(long)]
start: Option<String>,
},
/// Delete a meeting
Delete {
id: u64,
/// Skip confirmation prompt
#[arg(long)]
yes: bool,
},
/// End a live meeting
End { id: u64 },
/// List participants from a past meeting
Participants {
/// Meeting ID or UUID
meeting_id: String,
},
/// Get meeting invitation text
Invite { id: u64 },
}
#[derive(Subcommand)]
enum RecordingsCommand {
/// List cloud recordings for a user
List {
#[arg(long, default_value = "me")]
user: String,
#[arg(long)]
from: Option<String>,
#[arg(long)]
to: Option<String>,
#[arg(long)]
limit: Option<u32>,
#[arg(long)]
offset: Option<u32>,
#[arg(long, value_delimiter = ',')]
fields: Option<Vec<String>>,
},
/// Get recording details for a meeting
Get {
/// Meeting ID or UUID
meeting_id: String,
},
/// Download recording files for a meeting
Download {
/// Meeting ID or UUID
meeting_id: String,
#[arg(long, default_value = ".")]
out: String,
},
/// Delete all cloud recordings for a meeting
Delete {
/// Meeting ID or UUID
meeting_id: String,
/// Permanently delete instead of moving to trash (irreversible)
#[arg(long)]
permanent: bool,
/// Skip confirmation prompt
#[arg(long)]
yes: bool,
},
/// Start cloud recording for a live meeting
Start {
/// Numeric meeting ID of the live meeting
meeting_id: u64,
},
/// Stop cloud recording for a live meeting
Stop {
/// Numeric meeting ID of the live meeting
meeting_id: u64,
},
/// Pause cloud recording for a live meeting
Pause {
/// Numeric meeting ID of the live meeting
meeting_id: u64,
},
/// Resume cloud recording for a live meeting
Resume {
/// Numeric meeting ID of the live meeting
meeting_id: u64,
},
/// Download transcript files (VTT/chat) for a meeting
Transcript {
/// Meeting ID or UUID
meeting_id: String,
#[arg(long, default_value = ".")]
out: String,
},
}
#[derive(Subcommand)]
enum UsersCommand {
/// List users in the account
List {
#[arg(long)]
status: Option<String>,
#[arg(long)]
limit: Option<u32>,
#[arg(long)]
offset: Option<u32>,
#[arg(long, value_delimiter = ',')]
fields: Option<Vec<String>>,
},
/// Get a user by ID or email
Get { id_or_email: String },
/// Get the current user
Me,
/// Create a new user
Create {
#[arg(long)]
email: String,
#[arg(long)]
first_name: Option<String>,
#[arg(long)]
last_name: Option<String>,
/// User type: 1=Basic, 2=Licensed, 3=On-prem
#[arg(long, default_value = "1")]
r#type: u8,
},
/// Deactivate a user
Deactivate { id_or_email: String },
/// Activate (reactivate) a user
Activate { id_or_email: String },
}
#[derive(Subcommand)]
enum WebinarsCommand {
/// List webinars for a user
List {
#[arg(long, default_value = "me")]
user: String,
#[arg(long)]
limit: Option<u32>,
#[arg(long)]
offset: Option<u32>,
#[arg(long, value_delimiter = ',')]
fields: Option<Vec<String>>,
},
/// Get a webinar by ID
Get { id: u64 },
}
#[derive(Subcommand)]
enum ReportsCommand {
/// Meeting summary report for a user
Meetings {
#[arg(long, default_value = "me")]
user: String,
/// Start date (YYYY-MM-DD)
#[arg(long)]
from: String,
/// End date (YYYY-MM-DD, default: today)
#[arg(long)]
to: Option<String>,
#[arg(long)]
limit: Option<u32>,
#[arg(long)]
offset: Option<u32>,
#[arg(long, value_delimiter = ',')]
fields: Option<Vec<String>>,
},
/// Participant report for a past meeting
Participants {
/// Meeting ID or UUID
meeting_id: String,
},
}
#[tokio::main]
async fn main() {
let cli = match Cli::try_parse() {
Ok(c) => c,
Err(e) => {
// DisplayHelp and DisplayVersion are not errors — let clap handle them normally.
if matches!(
e.kind(),
clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion
) {
e.exit();
}
// For all real parse errors, emit a structured error envelope on stderr
// so the last non-empty line satisfies the CLI spec contract.
let envelope = serde_json::json!({
"error": {
"kind": "invalid_input",
"message": e.to_string().lines().next().unwrap_or("Parse error").trim().to_string(),
"retryable": false
}
});
eprintln!("{}", envelope);
// clap exits with code 2 for usage errors; preserve that.
std::process::exit(2);
}
};
let format = if cli.json {
OutputFormat::Json
} else {
match cli.output.as_str() {
"json" => OutputFormat::Json,
"text" => OutputFormat::Text,
_ => OutputFormat::Auto,
}
};
let out = OutputConfig::new(format, cli.quiet);
// These commands do not require credentials.
match &cli.command {
Command::Config(ConfigCommand::Show) => {
commands::config::show(cli.profile.as_deref(), &out);
return;
}
Command::Config(ConfigCommand::Delete { profile, force }) => {
if let Err(e) = commands::config::delete(profile, *force, &out) {
eprintln!("{}", e.to_structured_json());
std::process::exit(exit_codes::for_error(&e));
}
return;
}
Command::Init { profile } => {
if let Err(e) = commands::init::init(profile.clone()).await {
eprintln!("{}", e.to_structured_json());
std::process::exit(exit_codes::for_error(&e));
}
return;
}
Command::Schema => {
commands::schema();
return;
}
Command::Completions { shell } => {
clap_complete::generate(*shell, &mut Cli::command(), "zoom", &mut std::io::stdout());
return;
}
_ => {}
}
let cfg = match Config::load(cli.profile) {
Ok(c) => c,
Err(e) => {
eprintln!("{}", e.to_structured_json());
std::process::exit(exit_codes::CONFIG_ERROR);
}
};
let mut client = api::ZoomClient::new(cfg.account_id, cfg.client_id, cfg.client_secret);
let result = match cli.command {
Command::Meetings(cmd) => match cmd {
MeetingsCommand::List {
user,
r#type,
limit,
offset,
fields,
} => {
commands::meetings::list(
&mut client,
&out,
&user,
r#type.as_deref(),
limit,
offset,
fields.as_deref(),
)
.await
}
MeetingsCommand::Get { id } => commands::meetings::get(&mut client, &out, id).await,
MeetingsCommand::Create {
topic,
duration,
start,
password,
} => {
commands::meetings::create(&mut client, &out, topic, duration, start, password)
.await
}
MeetingsCommand::Update {
id,
topic,
duration,
start,
} => commands::meetings::update(&mut client, &out, id, topic, duration, start).await,
MeetingsCommand::Delete { id, yes } => {
commands::meetings::delete(&mut client, &out, id, yes).await
}
MeetingsCommand::End { id } => commands::meetings::end(&mut client, &out, id).await,
MeetingsCommand::Participants { meeting_id } => {
commands::meetings::participants(&mut client, &out, &meeting_id).await
}
MeetingsCommand::Invite { id } => {
commands::meetings::invite(&mut client, &out, id).await
}
},
Command::Recordings(cmd) => match cmd {
RecordingsCommand::List {
user,
from,
to,
limit,
offset,
fields,
} => {
commands::recordings::list(
&mut client,
&out,
&user,
from.as_deref(),
to.as_deref(),
limit,
offset,
fields.as_deref(),
)
.await
}
RecordingsCommand::Get { meeting_id } => {
commands::recordings::get(&mut client, &out, &meeting_id).await
}
RecordingsCommand::Download {
meeting_id,
out: out_dir,
} => commands::recordings::download(&mut client, &out, &meeting_id, &out_dir).await,
RecordingsCommand::Start { meeting_id } => {
commands::recordings::control(&mut client, &out, meeting_id, "start").await
}
RecordingsCommand::Stop { meeting_id } => {
commands::recordings::control(&mut client, &out, meeting_id, "stop").await
}
RecordingsCommand::Pause { meeting_id } => {
commands::recordings::control(&mut client, &out, meeting_id, "pause").await
}
RecordingsCommand::Resume { meeting_id } => {
commands::recordings::control(&mut client, &out, meeting_id, "resume").await
}
RecordingsCommand::Delete {
meeting_id,
permanent,
yes,
} => {
commands::recordings::delete(&mut client, &out, &meeting_id, !permanent, yes).await
}
RecordingsCommand::Transcript {
meeting_id,
out: out_dir,
} => commands::recordings::transcript(&mut client, &out, &meeting_id, &out_dir).await,
},
Command::Users(cmd) => match cmd {
UsersCommand::List {
status,
limit,
offset,
fields,
} => {
commands::users::list(
&mut client,
&out,
status.as_deref(),
limit,
offset,
fields.as_deref(),
)
.await
}
UsersCommand::Get { id_or_email } => {
commands::users::get(&mut client, &out, &id_or_email).await
}
UsersCommand::Me => commands::users::me(&mut client, &out).await,
UsersCommand::Create {
email,
first_name,
last_name,
r#type,
} => {
commands::users::create(&mut client, &out, email, first_name, last_name, r#type)
.await
}
UsersCommand::Deactivate { id_or_email } => {
commands::users::deactivate(&mut client, &out, &id_or_email).await
}
UsersCommand::Activate { id_or_email } => {
commands::users::activate(&mut client, &out, &id_or_email).await
}
},
Command::Reports(cmd) => match cmd {
ReportsCommand::Meetings {
user,
from,
to,
limit,
offset,
fields,
} => {
commands::reports::meetings(
&mut client,
&out,
&user,
&from,
to.as_deref(),
limit,
offset,
fields.as_deref(),
)
.await
}
ReportsCommand::Participants { meeting_id } => {
commands::reports::participants(&mut client, &out, &meeting_id).await
}
},
Command::Webinars(cmd) => match cmd {
WebinarsCommand::List {
user,
limit,
offset,
fields,
} => {
commands::webinars::list(&mut client, &out, &user, limit, offset, fields.as_deref())
.await
}
WebinarsCommand::Get { id } => commands::webinars::get(&mut client, &out, id).await,
},
Command::Config(ConfigCommand::Show | ConfigCommand::Delete { .. })
| Command::Init { .. }
| Command::Schema
| Command::Completions { .. } => {
unreachable!()
}
};
if let Err(e) = result {
eprintln!("{}", e.to_structured_json());
std::process::exit(exit_codes::for_error(&e));
}
}