atlassian-cli 0.4.1

Unified CLI for Atlassian Cloud products
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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
use anyhow::Result;
use atlassian_cli_api::ApiClient;
use atlassian_cli_output::OutputRenderer;
use clap::{Args, Subcommand};

// Submodules
mod analytics;
mod attachments;
mod bulk;
mod folders;
mod pages;
mod search;
mod spaces;
pub mod utils;

use utils::ConfluenceContext;

#[derive(Args, Debug, Clone)]
pub struct ConfluenceArgs {
    #[command(subcommand)]
    command: ConfluenceCommands,
}

#[derive(Subcommand, Debug, Clone)]
enum ConfluenceCommands {
    /// Space operations
    #[command(subcommand)]
    Space(SpaceCommands),

    /// Page operations
    #[command(subcommand)]
    Page(PageCommands),

    /// Folder operations (v2 Folder API)
    #[command(subcommand)]
    Folder(FolderCommands),

    /// Blog post operations
    #[command(subcommand)]
    Blog(BlogCommands),

    /// Attachment operations
    #[command(subcommand)]
    Attachment(AttachmentCommands),

    /// Search operations
    #[command(subcommand)]
    Search(SearchCommands),

    /// Bulk operations
    #[command(subcommand)]
    Bulk(BulkCommands),

    /// Analytics operations
    #[command(subcommand)]
    Analytics(AnalyticsCommands),
}

#[derive(Subcommand, Debug, Clone)]
enum SpaceCommands {
    /// List spaces
    #[command(
        long_about = "List spaces.\n\nExamples:\n  confluence space list\n  confluence space list --limit 50\n  confluence space list --space-type global"
    )]
    List {
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
        /// Filter by space type (global, personal)
        #[arg(long)]
        space_type: Option<String>,
    },
    /// Get space details
    #[command(long_about = "Get space details.\n\nExamples:\n  confluence space get TEAM")]
    Get {
        /// Space key (e.g., TEAM)
        key: String,
    },
    /// Create a new space
    #[command(
        long_about = "Create a new space.\n\nExamples:\n  confluence space create --key TEAM --name \"Team Space\"\n  confluence space create --key DOCS --name \"Documentation\" --description \"Project docs\""
    )]
    Create {
        /// Space key (e.g., TEAM)
        #[arg(long)]
        key: String,
        /// Space name
        #[arg(long)]
        name: String,
        /// Space description
        #[arg(long)]
        description: Option<String>,
    },
    /// Update space
    Update {
        /// Space ID
        space_id: String,
        /// New space name
        #[arg(long)]
        name: Option<String>,
        /// New space description
        #[arg(long)]
        description: Option<String>,
    },
    /// Delete space
    Delete {
        /// Space ID
        space_id: String,
        /// Force deletion without confirmation
        #[arg(long)]
        force: bool,
    },
    /// Get space permissions
    Permissions {
        /// Space key
        key: String,
    },
    /// Add space permission
    AddPermission {
        /// Space key
        key: String,
        /// Permission type (read, write, admin)
        #[arg(long)]
        permission: String,
        /// Subject type (user, group)
        #[arg(long)]
        subject_type: String,
        /// Subject identifier (user ID or group name)
        #[arg(long)]
        subject_id: String,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum FolderCommands {
    /// Get folder details by ID
    #[command(
        long_about = "Get folder details by ID.\n\nExamples:\n  confluence folder get 3309240341"
    )]
    Get {
        /// Folder ID
        folder_id: String,
    },
    /// Create a new folder
    #[command(
        long_about = "Create a folder in a space.\n\nExamples:\n  confluence folder create --space TEAM --title \"Architecture\"\n  confluence folder create --space TEAM --title \"Diagrams\" --parent 3302031761"
    )]
    Create {
        /// Space key (e.g., TEAM)
        #[arg(long)]
        space: String,
        /// Folder title
        #[arg(long)]
        title: String,
        /// Parent folder or page ID
        #[arg(long)]
        parent: Option<String>,
    },
    /// Delete a folder
    Delete {
        /// Folder ID
        folder_id: String,
        /// Force deletion without confirmation
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum PageCommands {
    /// List pages
    List {
        /// Filter by space key
        #[arg(long)]
        space: Option<String>,
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
    },
    /// Get page details
    Get {
        /// Page ID
        page_id: String,
        /// Output only the page body content (HTML or markdown)
        #[arg(long)]
        body_only: bool,
    },
    /// Create a new page
    Create {
        /// Space ID
        #[arg(long)]
        space: String,
        /// Page title
        #[arg(long)]
        title: String,
        /// Body content file (HTML storage format)
        #[arg(long)]
        body: Option<std::path::PathBuf>,
        /// Parent page ID
        #[arg(long)]
        parent: Option<String>,
    },
    /// Update a page
    Update {
        /// Page ID
        page_id: String,
        /// New page title
        #[arg(long)]
        title: Option<String>,
        /// New body content file (HTML storage format)
        #[arg(long)]
        body: Option<std::path::PathBuf>,
        /// Target status: current (published) or draft
        #[arg(long, value_parser = ["current", "draft"])]
        status: Option<String>,
        /// Version message for audit trail
        #[arg(long)]
        message: Option<String>,
    },
    /// Publish a draft page for the first time
    Publish {
        /// Page ID
        page_id: String,
        /// Body content file (HTML storage format) - required for publishing
        #[arg(long)]
        body: std::path::PathBuf,
        /// Page title (uses existing if not specified)
        #[arg(long)]
        title: Option<String>,
        /// Version message for audit trail
        #[arg(long)]
        message: Option<String>,
    },
    /// Delete a page
    Delete {
        /// Page ID
        page_id: String,
        /// Force deletion without confirmation
        #[arg(long)]
        force: bool,
    },
    /// List page versions
    Versions {
        /// Page ID
        page_id: String,
    },
    /// Add label to page
    AddLabel {
        /// Page ID
        page_id: String,
        /// Label name
        label: String,
    },
    /// Remove label from page
    RemoveLabel {
        /// Page ID
        page_id: String,
        /// Label name
        label: String,
    },
    /// List page comments
    Comments {
        /// Page ID
        page_id: String,
    },
    /// Add comment to page
    AddComment {
        /// Page ID
        page_id: String,
        /// Comment text
        comment: String,
    },
    /// Get page restrictions
    GetRestrictions {
        /// Page ID
        page_id: String,
    },
    /// Add page restriction
    AddRestriction {
        /// Page ID
        page_id: String,
        /// Operation (read, update)
        #[arg(long)]
        operation: String,
        /// Subject type (user, group)
        #[arg(long)]
        subject_type: String,
        /// Subject identifier (user ID or group name)
        #[arg(long)]
        subject_id: String,
    },
    /// Remove page restriction
    RemoveRestriction {
        /// Page ID
        page_id: String,
        /// Operation (read, update)
        #[arg(long)]
        operation: String,
        /// Subject type (user, group)
        #[arg(long)]
        subject_type: String,
        /// Subject identifier (user ID or group name)
        #[arg(long)]
        subject_id: String,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum BlogCommands {
    /// List blog posts
    List {
        /// Filter by space ID
        #[arg(long)]
        space: Option<String>,
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
    },
    /// Get blog post details
    Get {
        /// Blog post ID
        blogpost_id: String,
        /// Output only the blog post body content (HTML or markdown)
        #[arg(long)]
        body_only: bool,
    },
    /// Create a blog post
    Create {
        /// Space ID
        #[arg(long)]
        space: String,
        /// Blog post title
        #[arg(long)]
        title: String,
        /// Body content file (HTML storage format)
        #[arg(long)]
        body: Option<std::path::PathBuf>,
    },
    /// Update a blog post
    Update {
        /// Blog post ID
        blogpost_id: String,
        /// New blog post title
        #[arg(long)]
        title: Option<String>,
        /// New body content file (HTML storage format)
        #[arg(long)]
        body: Option<std::path::PathBuf>,
        /// Target status: current (published) or draft
        #[arg(long, value_parser = ["current", "draft"])]
        status: Option<String>,
        /// Version message for audit trail
        #[arg(long)]
        message: Option<String>,
    },
    /// Publish a draft blog post for the first time
    Publish {
        /// Blog post ID
        blogpost_id: String,
        /// Body content file (HTML storage format) - required for publishing
        #[arg(long)]
        body: std::path::PathBuf,
        /// Blog post title (uses existing if not specified)
        #[arg(long)]
        title: Option<String>,
        /// Version message for audit trail
        #[arg(long)]
        message: Option<String>,
    },
    /// Delete a blog post
    Delete {
        /// Blog post ID
        blogpost_id: String,
        /// Force deletion without confirmation
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum AttachmentCommands {
    /// List attachments for a page
    List {
        /// Page ID
        page_id: String,
    },
    /// Get attachment details
    Get {
        /// Attachment ID
        attachment_id: String,
    },
    /// Upload an attachment
    Upload {
        /// Page ID
        page_id: String,
        /// File path to upload
        #[arg(long)]
        file: std::path::PathBuf,
        /// Optional comment
        #[arg(long)]
        comment: Option<String>,
    },
    /// Download an attachment
    Download {
        /// Attachment ID
        attachment_id: String,
        /// Output file path
        #[arg(long)]
        output: std::path::PathBuf,
    },
    /// Delete an attachment
    Delete {
        /// Attachment ID
        attachment_id: String,
        /// Force deletion without confirmation
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum SearchCommands {
    /// Search using CQL
    #[command(
        long_about = "Search using CQL (Confluence Query Language).\n\nExamples:\n  confluence search cql 'space = TEAM AND type = page'\n  confluence search cql 'label = important' --limit 50"
    )]
    Cql {
        /// CQL query
        query: String,
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
    },
    /// Text search
    #[command(
        long_about = "Full text search.\n\nExamples:\n  confluence search text 'meeting notes'\n  confluence search text 'project update' --limit 20"
    )]
    Text {
        /// Search query
        query: String,
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
    },
    /// Search in space
    #[command(
        long_about = "Search within a specific space.\n\nExamples:\n  confluence search in-space TEAM 'release notes'\n  confluence search in-space DOCS 'api reference' --limit 10"
    )]
    InSpace {
        /// Space key (e.g., TEAM)
        space: String,
        /// Search query
        query: String,
        /// Maximum number of results
        #[arg(long)]
        limit: Option<usize>,
    },
    /// Search using filter parameters
    #[command(
        long_about = "Search using filter parameters.\n\nExamples:\n  confluence search params --space TEAM --type page\n  confluence search params --creator @me --label important"
    )]
    Params {
        /// Filter by space key
        #[arg(long)]
        space: Option<String>,

        /// Filter by content type (page, blogpost, attachment)
        #[arg(long)]
        r#type: Option<String>,

        /// Filter by creator (use @me for current user)
        #[arg(long)]
        creator: Option<String>,

        /// Filter by label (repeatable)
        #[arg(long, num_args = 0..)]
        label: Vec<String>,

        /// Search in title
        #[arg(long)]
        title: Option<String>,

        /// Free text search
        #[arg(long)]
        text: Option<String>,

        /// Display generated CQL query
        #[arg(long)]
        show_query: bool,

        /// Maximum number of results
        #[arg(long, default_value_t = 25)]
        limit: usize,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum BulkCommands {
    /// Bulk delete pages
    Delete {
        /// CQL query to select pages
        #[arg(long)]
        cql: String,
        /// Dry run mode
        #[arg(long)]
        dry_run: bool,
        /// Concurrency level
        #[arg(long, default_value_t = 4)]
        concurrency: usize,
    },
    /// Bulk add labels
    AddLabels {
        /// CQL query to select pages
        #[arg(long)]
        cql: String,
        /// Labels to add (comma-separated)
        #[arg(long, value_delimiter = ',')]
        labels: Vec<String>,
        /// Dry run mode
        #[arg(long)]
        dry_run: bool,
        /// Concurrency level
        #[arg(long, default_value_t = 4)]
        concurrency: usize,
    },
    /// Bulk export pages
    Export {
        /// CQL query to select pages
        #[arg(long)]
        cql: String,
        /// Output file path
        #[arg(long)]
        output: std::path::PathBuf,
        /// Export format: json or csv
        #[arg(long, default_value = "json")]
        format: String,
    },
}

#[derive(Subcommand, Debug, Clone)]
enum AnalyticsCommands {
    /// Get page view statistics
    PageViews {
        /// Page ID
        page_id: String,
        /// From date (YYYY-MM-DD)
        #[arg(long)]
        from: Option<String>,
    },
    /// Get space analytics
    SpaceStats {
        /// Space key
        space_key: String,
    },
}

pub async fn execute(
    args: ConfluenceArgs,
    client: ApiClient,
    renderer: &OutputRenderer,
) -> Result<()> {
    let ctx = ConfluenceContext { client, renderer };

    match args.command {
        ConfluenceCommands::Space(cmd) => match cmd {
            SpaceCommands::List { limit, space_type } => {
                spaces::list_spaces(&ctx, limit, space_type.as_deref()).await
            }
            SpaceCommands::Get { key } => spaces::get_space(&ctx, &key).await,
            SpaceCommands::Create {
                key,
                name,
                description,
            } => spaces::create_space(&ctx, &key, &name, description.as_deref()).await,
            SpaceCommands::Update {
                space_id,
                name,
                description,
            } => {
                spaces::update_space(&ctx, &space_id, name.as_deref(), description.as_deref()).await
            }
            SpaceCommands::Delete { space_id, force } => {
                spaces::delete_space(&ctx, &space_id, force).await
            }
            SpaceCommands::Permissions { key } => spaces::get_space_permissions(&ctx, &key).await,
            SpaceCommands::AddPermission {
                key,
                permission,
                subject_type,
                subject_id,
            } => {
                spaces::add_space_permission(&ctx, &key, &permission, &subject_type, &subject_id)
                    .await
            }
        },
        ConfluenceCommands::Page(cmd) => match cmd {
            PageCommands::List { space, limit } => {
                pages::list_pages(&ctx, space.as_deref(), limit).await
            }
            PageCommands::Get { page_id, body_only } => {
                pages::get_page(&ctx, &page_id, body_only).await
            }
            PageCommands::Create {
                space,
                title,
                body,
                parent,
            } => pages::create_page(&ctx, &space, &title, body.as_ref(), parent.as_deref()).await,
            PageCommands::Update {
                page_id,
                title,
                body,
                status,
                message,
            } => {
                pages::update_page(
                    &ctx,
                    &page_id,
                    title.as_deref(),
                    body.as_ref(),
                    status.as_deref(),
                    message.as_deref(),
                )
                .await
            }
            PageCommands::Publish {
                page_id,
                body,
                title,
                message,
            } => {
                pages::publish_page(&ctx, &page_id, title.as_deref(), &body, message.as_deref())
                    .await
            }
            PageCommands::Delete { page_id, force } => {
                pages::delete_page(&ctx, &page_id, force).await
            }
            PageCommands::Versions { page_id } => pages::list_page_versions(&ctx, &page_id).await,
            PageCommands::AddLabel { page_id, label } => {
                pages::add_page_label(&ctx, &page_id, &label).await
            }
            PageCommands::RemoveLabel { page_id, label } => {
                pages::remove_page_label(&ctx, &page_id, &label).await
            }
            PageCommands::Comments { page_id } => pages::list_page_comments(&ctx, &page_id).await,
            PageCommands::AddComment { page_id, comment } => {
                pages::add_page_comment(&ctx, &page_id, &comment).await
            }
            PageCommands::GetRestrictions { page_id } => {
                pages::get_page_restrictions(&ctx, &page_id).await
            }
            PageCommands::AddRestriction {
                page_id,
                operation,
                subject_type,
                subject_id,
            } => {
                pages::add_page_restriction(&ctx, &page_id, &operation, &subject_type, &subject_id)
                    .await
            }
            PageCommands::RemoveRestriction {
                page_id,
                operation,
                subject_type,
                subject_id,
            } => {
                pages::remove_page_restriction(
                    &ctx,
                    &page_id,
                    &operation,
                    &subject_type,
                    &subject_id,
                )
                .await
            }
        },
        ConfluenceCommands::Folder(cmd) => match cmd {
            FolderCommands::Get { folder_id } => folders::get_folder(&ctx, &folder_id).await,
            FolderCommands::Create {
                space,
                title,
                parent,
            } => folders::create_folder(&ctx, &space, &title, parent.as_deref()).await,
            FolderCommands::Delete { folder_id, force } => {
                folders::delete_folder(&ctx, &folder_id, force).await
            }
        },
        ConfluenceCommands::Blog(cmd) => match cmd {
            BlogCommands::List { space, limit } => {
                pages::list_blogposts(&ctx, space.as_deref(), limit).await
            }
            BlogCommands::Get {
                blogpost_id,
                body_only,
            } => pages::get_blogpost(&ctx, &blogpost_id, body_only).await,
            BlogCommands::Create { space, title, body } => {
                pages::create_blog(&ctx, &space, &title, body.as_ref()).await
            }
            BlogCommands::Update {
                blogpost_id,
                title,
                body,
                status,
                message,
            } => {
                pages::update_blogpost(
                    &ctx,
                    &blogpost_id,
                    title.as_deref(),
                    body.as_ref(),
                    status.as_deref(),
                    message.as_deref(),
                )
                .await
            }
            BlogCommands::Publish {
                blogpost_id,
                body,
                title,
                message,
            } => {
                pages::publish_blogpost(
                    &ctx,
                    &blogpost_id,
                    title.as_deref(),
                    &body,
                    message.as_deref(),
                )
                .await
            }
            BlogCommands::Delete { blogpost_id, force } => {
                pages::delete_blogpost(&ctx, &blogpost_id, force).await
            }
        },
        ConfluenceCommands::Attachment(cmd) => match cmd {
            AttachmentCommands::List { page_id } => {
                attachments::list_attachments(&ctx, &page_id).await
            }
            AttachmentCommands::Get { attachment_id } => {
                attachments::get_attachment(&ctx, &attachment_id).await
            }
            AttachmentCommands::Upload {
                page_id,
                file,
                comment,
            } => attachments::upload_attachment(&ctx, &page_id, &file, comment.as_deref()).await,
            AttachmentCommands::Download {
                attachment_id,
                output,
            } => attachments::download_attachment(&ctx, &attachment_id, &output).await,
            AttachmentCommands::Delete {
                attachment_id,
                force,
            } => attachments::delete_attachment(&ctx, &attachment_id, force).await,
        },
        ConfluenceCommands::Search(cmd) => match cmd {
            SearchCommands::Cql { query, limit } => search::search_cql(&ctx, &query, limit).await,
            SearchCommands::Text { query, limit } => search::search_text(&ctx, &query, limit).await,
            SearchCommands::InSpace {
                space,
                query,
                limit,
            } => search::search_in_space(&ctx, &space, &query, limit).await,
            SearchCommands::Params {
                space,
                r#type,
                creator,
                label,
                title,
                text,
                show_query,
                limit,
            } => {
                search::search_params(
                    &ctx,
                    space.as_deref(),
                    r#type.as_deref(),
                    creator.as_deref(),
                    &label,
                    title.as_deref(),
                    text.as_deref(),
                    show_query,
                    limit,
                )
                .await
            }
        },
        ConfluenceCommands::Bulk(cmd) => match cmd {
            BulkCommands::Delete {
                cql,
                dry_run,
                concurrency,
            } => bulk::bulk_delete_pages(&ctx, &cql, dry_run, concurrency).await,
            BulkCommands::AddLabels {
                cql,
                labels,
                dry_run,
                concurrency,
            } => bulk::bulk_add_labels(&ctx, &cql, labels, dry_run, concurrency).await,
            BulkCommands::Export {
                cql,
                output,
                format,
            } => {
                let export_format = match format.to_lowercase().as_str() {
                    "json" => bulk::ExportFormat::Json,
                    "csv" => bulk::ExportFormat::Csv,
                    _ => {
                        return Err(anyhow::anyhow!(
                            "Invalid format '{}'. Must be one of: json, csv",
                            format
                        ))
                    }
                };
                bulk::bulk_export_pages(&ctx, &cql, &output, export_format).await
            }
        },
        ConfluenceCommands::Analytics(cmd) => match cmd {
            AnalyticsCommands::PageViews { page_id, from } => {
                analytics::get_page_views(&ctx, &page_id, from.as_deref()).await
            }
            AnalyticsCommands::SpaceStats { space_key } => {
                analytics::get_space_analytics(&ctx, &space_key).await
            }
        },
    }
}