aimcal-cli 0.12.1

AIM - Analyze. Interact. Manage Your Time, with calendar support
Documentation
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
// SPDX-FileCopyrightText: 2025-2026 Zexin Yuan <aim@yzx9.xyz>
//
// SPDX-License-Identifier: Apache-2.0

use std::{error::Error, ffi::OsString, path::PathBuf};

use aimcal_core::{APP_NAME, Aim};
use clap::{ArgMatches, Command, ValueHint, arg, builder::styling, crate_version, value_parser};
use colored::Colorize;
use futures::{FutureExt, future::BoxFuture};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{EnvFilter, Registry, prelude::*};

use crate::cmd_calendar::{CmdCalendarList, CmdCalendarShow};
use crate::cmd_event::{
    CmdEventDelay, CmdEventEdit, CmdEventList, CmdEventNew, CmdEventReschedule,
};
use crate::cmd_generate_completion::CmdGenerateCompletion;
use crate::cmd_todo::{
    CmdTodoCancel, CmdTodoDelay, CmdTodoDone, CmdTodoEdit, CmdTodoList, CmdTodoNew,
    CmdTodoReschedule, CmdTodoUndo,
};
use crate::cmd_toplevel::{CmdDashboard, CmdDelay, CmdFlush, CmdReschedule};
use crate::cmd_tui::{CmdEdit, CmdNew};
use crate::config::parse_config;

/// Run the AIM command-line interface.
///
/// # Errors
/// If an error occurs while running the CLI
pub async fn run() -> Result<(), Box<dyn Error>> {
    init_tracing()?;

    // Prevent Ctrl+C from killing the process during interactive prompts (cliclack).
    // Without this handler, the `console` crate's internal `raise(SIGINT)` terminates
    // the process before cliclack can restore the cursor. See fadeevab/cliclack#84.
    ctrlc::set_handler(move || {})?;

    let err = match Cli::parse() {
        Ok(cli) => match cli.run().await {
            Ok(()) => return Ok(()),
            Err(e) => e,
        },
        Err(e) => e,
    };
    println!("{} {}", "Error:".red(), err);
    Ok(())
}

pub fn init_tracing() -> Result<(), Box<dyn Error>> {
    let stdout_log = tracing_subscriber::fmt::layer().pretty();

    let filter = EnvFilter::builder()
        .with_default_directive(LevelFilter::ERROR.into())
        .from_env_lossy();

    let subscriber = Registry::default().with(filter).with(stdout_log);

    tracing::subscriber::set_global_default(subscriber)?;
    Ok(())
}

/// Command-line interface
#[derive(Debug)]
pub struct Cli {
    /// Path to the configuration file
    pub config: Option<PathBuf>,

    /// The command to execute
    pub command: Commands,
}

impl Cli {
    /// Create the command-line interface
    #[must_use]
    pub fn command() -> Command {
        const STYLES: styling::Styles = styling::Styles::styled()
            .header(styling::AnsiColor::Green.on_default().bold())
            .usage(styling::AnsiColor::Green.on_default().bold())
            .literal(styling::AnsiColor::Blue.on_default().bold())
            .placeholder(styling::AnsiColor::Cyan.on_default());

        Command::new(APP_NAME)
            .about("Analyze. Interact. Manage Your Time, with calendar support.")
            .author("Zexin Yuan <aim@yzx9.xyz>")
            .version(crate_version!())
            .styles(STYLES)
            .subcommand_required(false) // allow default to dashboard
            .arg_required_else_help(false)
            .arg(
                arg!(-c --config [CONFIG] "Path to the configuration file")
                    .long_help(
                        "\
Path to the configuration file. Can be specified via AIM_CONFIG environment variable. \
Defaults to $XDG_CONFIG_HOME/aim/config.toml on Linux and MacOS, \
%LOCALAPPDATA%/aim/config.toml on Windows.",
                    )
                    .value_parser(value_parser!(PathBuf))
                    .value_hint(ValueHint::FilePath),
            )
            .subcommand(CmdDashboard::command())
            .subcommand(CmdNew::command())
            .subcommand(CmdEdit::command())
            .subcommand(CmdDelay::command())
            .subcommand(CmdReschedule::command())
            .subcommand(
                Command::new("calendar")
                    .about("Manage calendars")
                    .arg_required_else_help(true)
                    .subcommand_required(true)
                    .subcommand(CmdCalendarList::command())
                    .subcommand(CmdCalendarShow::command()),
            )
            .subcommand(
                Command::new("event")
                    .alias("e")
                    .about("Manage your event list")
                    .arg_required_else_help(true)
                    .subcommand_required(true)
                    .subcommand(CmdEventNew::command())
                    .subcommand(CmdEventEdit::command())
                    .subcommand(CmdEventDelay::command())
                    .subcommand(CmdEventReschedule::command())
                    .subcommand(CmdEventList::command()),
            )
            .subcommand(
                Command::new("todo")
                    .alias("t")
                    .about("Manage your todo list")
                    .arg_required_else_help(true)
                    .subcommand_required(true)
                    .subcommand(CmdTodoNew::command())
                    .subcommand(CmdTodoEdit::command())
                    .subcommand(CmdTodoDone::command())
                    .subcommand(CmdTodoUndo::command())
                    .subcommand(CmdTodoCancel::command())
                    .subcommand(CmdTodoDelay::command())
                    .subcommand(CmdTodoReschedule::command())
                    .subcommand(CmdTodoList::command()),
            )
            .subcommand(CmdTodoDone::command())
            .subcommand(CmdFlush::command())
            .subcommand(CmdGenerateCompletion::command())
    }

    /// Parse the command-line arguments
    ///
    /// # Errors
    /// If an error occurs while parsing the arguments
    pub fn parse() -> Result<Self, Box<dyn Error>> {
        let commands = Self::command();
        let matches = commands.get_matches();
        Self::from(&matches)
    }

    /// Parse the specified arguments
    ///
    /// # Errors
    /// If an error occurs while parsing the arguments
    pub fn try_parse_from<I, T>(args: I) -> Result<Self, Box<dyn Error>>
    where
        I: IntoIterator<Item = T>,
        T: Into<OsString> + Clone,
    {
        let commands = Self::command();
        let matches = commands.try_get_matches_from(args)?;
        Self::from(&matches)
    }

    /// Create a CLI instance from the `ArgMatches`
    ///
    /// # Errors
    /// If an error occurs while parsing the arguments
    pub fn from(matches: &ArgMatches) -> Result<Self, Box<dyn Error>> {
        use Commands::{
            CalendarList, CalendarShow, Dashboard, Delay, Edit, EventDelay, EventEdit, EventList,
            EventNew, EventReschedule, Flush, GenerateCompletion, New, Reschedule, TodoCancel,
            TodoDelay, TodoDone, TodoEdit, TodoList, TodoNew, TodoReschedule, TodoUndo,
        };
        let command = match matches.subcommand() {
            Some((CmdDashboard::NAME, matches)) => Dashboard(CmdDashboard::from(matches)),
            Some((CmdNew::NAME, matches)) => New(CmdNew::from(matches)),
            Some((CmdEdit::NAME, matches)) => Edit(CmdEdit::from(matches)),
            Some((CmdDelay::NAME, matches)) => Delay(CmdDelay::from(matches)),
            Some((CmdReschedule::NAME, matches)) => Reschedule(CmdReschedule::from(matches)),
            Some((CmdFlush::NAME, matches)) => Flush(CmdFlush::from(matches)),
            Some(("calendar", matches)) => match matches.subcommand() {
                Some((CmdCalendarList::NAME, matches)) => {
                    CalendarList(CmdCalendarList::from(matches))
                }
                Some((CmdCalendarShow::NAME, matches)) => {
                    CalendarShow(CmdCalendarShow::from(matches))
                }
                _ => unreachable!(),
            },
            Some(("event", matches)) => match matches.subcommand() {
                Some((CmdEventNew::NAME, matches)) => EventNew(CmdEventNew::from(matches)),
                Some((CmdEventEdit::NAME, matches)) => EventEdit(CmdEventEdit::from(matches)),
                Some((CmdEventDelay::NAME, matches)) => EventDelay(CmdEventDelay::from(matches)),
                Some((CmdEventReschedule::NAME, matches)) => {
                    EventReschedule(CmdEventReschedule::from(matches))
                }
                Some((CmdEventList::NAME, matches)) => EventList(CmdEventList::from(matches)),
                _ => unreachable!(),
            },
            Some(("todo", matches)) => match matches.subcommand() {
                Some((CmdTodoNew::NAME, matches)) => TodoNew(CmdTodoNew::from(matches)),
                Some((CmdTodoEdit::NAME, matches)) => TodoEdit(CmdTodoEdit::from(matches)),
                Some((CmdTodoUndo::NAME, matches)) => TodoUndo(CmdTodoUndo::from(matches)),
                Some((CmdTodoDone::NAME, matches)) => TodoDone(CmdTodoDone::from(matches)),
                Some((CmdTodoCancel::NAME, matches)) => TodoCancel(CmdTodoCancel::from(matches)),
                Some((CmdTodoDelay::NAME, matches)) => TodoDelay(CmdTodoDelay::from(matches)),
                Some((CmdTodoReschedule::NAME, matches)) => {
                    TodoReschedule(CmdTodoReschedule::from(matches))
                }
                Some((CmdTodoList::NAME, matches)) => TodoList(CmdTodoList::from(matches)),
                _ => unreachable!(),
            },
            Some((CmdTodoDone::NAME, matches)) => TodoDone(CmdTodoDone::from(matches)),
            Some((CmdGenerateCompletion::NAME, matches)) => {
                GenerateCompletion(CmdGenerateCompletion::from(matches))
            }
            None => Dashboard(CmdDashboard),
            _ => unreachable!(),
        };

        let config = matches.get_one("config").cloned();
        Ok(Cli { config, command })
    }

    /// Run the command
    ///
    /// # Errors
    /// If an error occurs while running the command
    pub async fn run(self) -> Result<(), Box<dyn Error>> {
        self.command.run(self.config).await
    }
}

/// The commands available in the CLI
#[derive(Debug, Clone)]
pub enum Commands {
    /// List calendars
    CalendarList(CmdCalendarList),

    /// Show detailed calendar information
    CalendarShow(CmdCalendarShow),

    /// Show the dashboard
    Dashboard(CmdDashboard),

    /// New a event or todo
    New(CmdNew),

    /// Edit a event or todo
    Edit(CmdEdit),

    /// Delay an event or todo based on original time
    Delay(CmdDelay),

    /// Reschedule an event or todo based on current time
    Reschedule(CmdReschedule),

    /// Flush the short IDs
    Flush(CmdFlush),

    /// Add a new event
    EventNew(CmdEventNew),

    /// Edit an event
    EventEdit(CmdEventEdit),

    /// Delay an event based on original start
    EventDelay(CmdEventDelay),

    /// Reschedule an event based on current time
    EventReschedule(CmdEventReschedule),

    /// List events
    EventList(CmdEventList),

    /// Add a new todo
    TodoNew(CmdTodoNew),

    /// Edit a todo
    TodoEdit(CmdTodoEdit),

    /// Mark a todo as needs-action
    TodoUndo(CmdTodoUndo),

    /// Mark a todo as completed
    TodoDone(CmdTodoDone),

    /// Mark a todo as cancelled
    TodoCancel(CmdTodoCancel),

    /// Delay a todo based on original due
    TodoDelay(CmdTodoDelay),

    /// Reschedule a todo based on current time
    TodoReschedule(CmdTodoReschedule),

    /// List todos
    TodoList(CmdTodoList),

    /// Generate shell completion
    GenerateCompletion(CmdGenerateCompletion),
}

impl Commands {
    /// Run the command with the given configuration
    ///
    /// # Errors
    /// If an error occurs while running the command
    #[rustfmt::skip]
    #[tracing::instrument(skip_all, fields(trace_id = %uuid::Uuid::new_v4()))]
    pub async fn run(self, config: Option<PathBuf>) -> Result<(), Box<dyn Error>> {
        use Commands::{
            CalendarList, CalendarShow, Dashboard, Delay, Edit, EventDelay, EventEdit,
            EventList, EventNew, EventReschedule, Flush, GenerateCompletion, New, Reschedule,
            TodoCancel, TodoDelay, TodoDone, TodoEdit, TodoList, TodoNew, TodoReschedule,
            TodoUndo,
        };
        tracing::info!(?self, "running command");
        match self {
            CalendarList(a)    => Self::run_with(config, |x| a.run(x).boxed()).await,
            CalendarShow(a)    => Self::run_with(config, |x| a.run(x).boxed()).await,
            Dashboard(a)       => Self::run_with(config, |x| a.run(x).boxed()).await,
            New(a)             => Self::run_with(config, |x| a.run(x).boxed()).await,
            Edit(a)            => Self::run_with(config, |x| a.run(x).boxed()).await,
            Delay(a)           => Self::run_with(config, |x| a.run(x).boxed()).await,
            Reschedule(a)      => Self::run_with(config, |x| a.run(x).boxed()).await,
            Flush(a)           => Self::run_with(config, |x| a.run(x).boxed()).await,
            EventNew(a)        => Self::run_with(config, |x| a.run(x).boxed()).await,
            EventEdit(a)       => Self::run_with(config, |x| a.run(x).boxed()).await,
            EventDelay(a)      => Self::run_with(config, |x| a.run(x).boxed()).await,
            EventReschedule(a) => Self::run_with(config, |x| a.run(x).boxed()).await,
            EventList(a)       => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoNew(a)         => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoEdit(a)        => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoUndo(a)        => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoDone(a)        => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoCancel(a)      => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoDelay(a)       => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoReschedule(a)  => Self::run_with(config, |x| a.run(x).boxed()).await,
            TodoList(a)        => Self::run_with(config, |x| a.run(x).boxed()).await,
            GenerateCompletion(a) => { a.run(); Ok(()) }
        }
    }

    async fn run_with<F>(config: Option<PathBuf>, f: F) -> Result<(), Box<dyn Error>>
    where
        F: for<'a> FnOnce(&'a mut Aim) -> BoxFuture<'a, Result<(), Box<dyn Error>>>,
    {
        tracing::debug!("parsing configuration...");
        let (core_config, _config) = parse_config(config).await?;

        tracing::debug!("instantiating...");
        let mut aim = Aim::new(core_config).await?;
        for notice in aim.startup_notices() {
            println!("Note: {notice}");
        }

        tracing::debug!("running command...");
        f(&mut aim).await?;

        tracing::debug!("closing...");
        aim.close().await?;
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use aimcal_core::Id;

    use crate::{cmd_generate_completion::Shell, util::OutputFormat};

    use super::*;

    #[test]
    fn parses_config_command() {
        let args = ["test", "-c", "/tmp/config.toml"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert_eq!(cli.config, Some(PathBuf::from("/tmp/config.toml")));
        assert!(matches!(cli.command, Commands::Dashboard(_)));
    }

    #[test]
    fn parses_default_dashboard_command() {
        let args = ["test"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::Dashboard(_)));
    }

    #[test]
    fn parses_dashboard_command() {
        let args = ["test", "dashboard"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::Dashboard(_)));
    }

    #[test]
    fn parses_new_command() {
        let args = ["test", "new"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::New(_)));
    }

    #[test]
    fn parses_add_command() {
        let args = ["test", "add"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::New(_)));
    }

    #[test]
    fn parses_edit_command() {
        let args = ["test", "edit", "id1"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::Edit(_)));
    }

    #[test]
    fn parses_flush_command() {
        let args = ["test", "flush"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::Flush(_)));
    }

    #[test]
    fn parses_event_new_command() {
        let cli = Cli::try_parse_from([
            "test",
            "event",
            "new",
            "a new event",
            "--calendar",
            "work",
            "--start",
            "2025-01-01 10:00",
            "--end",
            "2025-01-01 12:00",
        ])
        .unwrap();
        assert!(matches!(cli.command, Commands::EventNew(_)));
    }

    #[test]
    fn parses_event_add_command() {
        let args = [
            "test",
            "event",
            "add",
            "a new event",
            "--start",
            "2025-01-01 10:00",
            "--end",
            "2025-01-01 12:00",
        ];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::EventNew(_)));
    }

    #[test]
    fn parses_event_edit_command() {
        let args = ["test", "event", "edit", "some_id", "-s", "new summary"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::EventEdit(cmd) => {
                assert_eq!(cmd.id, Id::ShortIdOrUid("some_id".to_string()));
                assert_eq!(cmd.summary, Some("new summary".to_string()));
            }
            _ => panic!("Expected EventEdit command"),
        }
    }

    #[test]
    fn parses_event_delay_command() {
        let args = ["test", "event", "delay", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::EventDelay(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected EventDelay command"),
        }
    }

    #[test]
    fn parses_event_reschedule_command() {
        let args = ["test", "event", "reschedule", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::EventReschedule(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected EventReschedule command"),
        }
    }

    #[test]
    fn parses_event_list_command() {
        let args = ["test", "event", "list", "--output-format", "json"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::EventList(cmd) => assert_eq!(cmd.output_format, OutputFormat::Json),
            _ => panic!("Expected EventList command"),
        }
    }

    #[test]
    fn parses_todo_new_command() {
        let args = ["test", "todo", "new", "a new todo"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::TodoNew(_)));
    }

    #[test]
    fn parses_todo_add_command() {
        let args = ["test", "todo", "add", "a new todo"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::TodoNew(_)));
    }

    #[test]
    fn parses_todo_edit_command() {
        let args = ["test", "todo", "edit", "some_id", "-s", "new summary"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoEdit(cmd) => {
                assert_eq!(cmd.id, Id::ShortIdOrUid("some_id".to_string()));
                assert_eq!(cmd.summary, Some("new summary".to_string()));
            }
            _ => panic!("Expected TodoEdit command"),
        }
    }

    #[test]
    fn parses_todo_undo_command() {
        let args = ["test", "todo", "undo", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoUndo(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoUndo command"),
        }
    }

    #[test]
    fn parses_todo_done_command() {
        let args = ["test", "todo", "done", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoDone(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoDone command"),
        }
    }

    #[test]
    fn parses_todo_cancel_command() {
        let args = ["test", "todo", "cancel", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoCancel(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoDone command"),
        }
    }

    #[test]
    fn parses_todo_delay_command() {
        let args = ["test", "todo", "delay", "id1", "id2", "id3"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoDelay(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                    Id::ShortIdOrUid("id3".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoDelay command"),
        }
    }

    #[test]
    fn parses_todo_reschedule_command() {
        let args = ["test", "todo", "reschedule", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoReschedule(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoReschedule command"),
        }
    }

    #[test]
    fn parses_todo_list_command() {
        let args = ["test", "todo", "list", "--output-format", "json"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoList(cmd) => assert_eq!(cmd.output_format, OutputFormat::Json),
            _ => panic!("Expected TodoList command"),
        }
    }

    #[test]
    fn parses_calendar_list_command() {
        let args = ["test", "calendar", "list", "--output-format", "json"];
        let cli = Cli::try_parse_from(args).unwrap();
        assert!(matches!(cli.command, Commands::CalendarList(_)));
    }

    #[test]
    fn parses_calendar_show_command() {
        let args = [
            "test",
            "calendar",
            "show",
            "work",
            "--output-format",
            "json",
        ];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::CalendarShow(cmd) => {
                assert_eq!(cmd.id, "work");
                assert_eq!(cmd.output_format, OutputFormat::Json);
            }
            _ => panic!("Expected CalendarShow command"),
        }
    }

    #[test]
    fn parses_done_command() {
        let args = ["test", "done", "id1", "id2"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::TodoDone(cmd) => {
                let expected_ids = [
                    Id::ShortIdOrUid("id1".to_string()),
                    Id::ShortIdOrUid("id2".to_string()),
                ];
                assert_eq!(cmd.ids, expected_ids);
            }
            _ => panic!("Expected TodoDone command"),
        }
    }

    #[test]
    fn parses_generate_completion_command() {
        let args = ["test", "generate-completion", "zsh"];
        let cli = Cli::try_parse_from(args).unwrap();
        match cli.command {
            Commands::GenerateCompletion(cmd) => assert_eq!(cmd.shell, Shell::Zsh),
            _ => panic!("Expected GenerateCompletion command"),
        }
    }
}