forgejo-cli 0.4.0

CLI tool for Forgejo
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
use clap::{Args, Subcommand};
use eyre::OptionExt;
use forgejo_api::{
    structs::{
        CreateLabelOption, CreateOrgOption, EditLabelOption, EditOrgOption, OrgListLabelsQuery,
    },
    Forgejo,
};
use futures::{future, TryStreamExt};

use crate::{repo::RepoInfo, SpecialRender};

mod team;

#[derive(Args, Clone, Debug)]
pub struct OrgCommand {
    /// The local git remote that points to the repo to operate on.
    #[clap(long, short = 'R')]
    remote: Option<String>,
    #[clap(subcommand)]
    command: OrgSubcommand,
}

#[derive(Subcommand, Clone, Debug)]
pub enum OrgSubcommand {
    /// List all organizations
    List {
        /// Which page of the results to view
        #[clap(long, short, default_value_t = 1)]
        page: u32,
        /// Only list organizations you are a member of.
        #[clap(long, short, conflicts_with = "page")]
        only_member_of: bool,
    },
    /// View info about an organization
    View {
        /// The name of the organization to view.
        name: String,
    },
    /// Create a new organization
    Create {
        /// The username for the organization.
        ///
        /// It can only have alphanumeric characters, dash, underscore, or period. It must start
        /// and end with an alphanumeric character, and can't have consecutive dashes, underscores,
        /// or periods.
        ///
        /// If you want a name that doesn't have these restrictions, see the `--full-name` option.
        name: String,
        #[clap(flatten)]
        options: OrgOptions,
    },
    /// Edit an organization's information.
    Edit {
        /// The name of the organization to edit.
        ///
        /// Note that this is the username, *not* the display name.
        name: String,
        #[clap(flatten)]
        options: OrgOptions,
    },
    /// View the activity in an organization
    Activity {
        /// The name of the organization to view activity for.
        name: String,
    },
    /// List the members of an organization
    Members {
        /// The name of the organization to view the members of.
        org: String,
        /// Which page of the results to view
        #[clap(long, short, default_value_t = 1)]
        page: u32,
    },
    /// View and change the visibility of your membership in an organization
    Visibility {
        /// The name of the organization to view your visibility in.
        org: String,
        /// Set a new visibility for yourself.
        #[clap(long, short)]
        set: Option<OrgMemberVisibility>,
    },
    #[clap(subcommand)]
    Team(team::TeamSubcommand),
    #[clap(subcommand)]
    Label(LabelSubcommand),
    #[clap(subcommand)]
    Repo(RepoSubcommand),
}

#[derive(Args, Clone, Debug)]
pub struct OrgOptions {
    /// The display name for the organization.
    ///
    /// This doesn't have the restrictions the `name` argument does, and can contain any UTF-8
    /// text.
    #[clap(long, short)]
    full_name: Option<String>,
    /// The organization's description
    #[clap(long, short)]
    description: Option<String>,
    /// Contact email for the organization
    #[clap(long, short)]
    email: Option<String>,
    /// The organizations's location
    #[clap(long, short)]
    location: Option<String>,
    /// The organization's website
    #[clap(long, short)]
    website: Option<String>,
    /// The visibility of the organization.
    ///
    /// Public organizations can be viewed by anyone, limited orgs can only be viewed by
    /// logged-in users, and private orgs can only be viewed by members of that org.
    #[clap(long, short)]
    visibility: Option<OrgVisibility>,
    /// Whether the admin of a repo can change org teams' access to it.
    #[clap(long, short)]
    admin_can_change_team_access: Option<bool>,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum OrgMemberVisibility {
    Private,
    Public,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum OrgVisibility {
    Private,
    Limited,
    Public,
}

impl Into<forgejo_api::structs::CreateOrgOptionVisibility> for OrgVisibility {
    fn into(self) -> forgejo_api::structs::CreateOrgOptionVisibility {
        use forgejo_api::structs::CreateOrgOptionVisibility as ApiVis;
        match self {
            OrgVisibility::Private => ApiVis::Private,
            OrgVisibility::Limited => ApiVis::Limited,
            OrgVisibility::Public => ApiVis::Public,
        }
    }
}

impl Into<forgejo_api::structs::EditOrgOptionVisibility> for OrgVisibility {
    fn into(self) -> forgejo_api::structs::EditOrgOptionVisibility {
        use forgejo_api::structs::EditOrgOptionVisibility as ApiVis;
        match self {
            OrgVisibility::Private => ApiVis::Private,
            OrgVisibility::Limited => ApiVis::Limited,
            OrgVisibility::Public => ApiVis::Public,
        }
    }
}

impl OrgCommand {
    pub async fn run(self, keys: &mut crate::KeyInfo, host_name: Option<&str>) -> eyre::Result<()> {
        let repo = RepoInfo::get_current(host_name, None, self.remote.as_deref(), &keys)?;
        let api = keys.get_api(repo.host_url()).await?;
        match self.command {
            OrgSubcommand::List {
                page,
                only_member_of,
            } => list_orgs(&api, page, only_member_of).await?,
            OrgSubcommand::View { name } => view_org(&api, name).await?,
            OrgSubcommand::Create { name, options } => create_org(&api, name, options).await?,
            OrgSubcommand::Edit { name, options } => edit_org(&api, name, options).await?,
            OrgSubcommand::Activity { name } => list_activity(&api, name).await?,
            OrgSubcommand::Members { org, page } => list_org_members(&api, org, page).await?,
            OrgSubcommand::Visibility { org, set } => member_visibility(&api, org, set).await?,
            OrgSubcommand::Team(subcommand) => subcommand.run(&api).await?,
            OrgSubcommand::Label(subcommand) => subcommand.run(&api).await?,
            OrgSubcommand::Repo(subcommand) => subcommand.run(keys, &repo, &api).await?,
        }
        Ok(())
    }
}

fn is_valid_name_char(c: char) -> bool {
    match c {
        '-' | '_' | '.' => true,
        _ => c.is_ascii_alphanumeric(),
    }
}

async fn list_orgs(api: &Forgejo, page: u32, only_member_of: bool) -> eyre::Result<()> {
    let (total, orgs) = if only_member_of {
        let orgs = api.org_list_current_user_orgs().await?;
        (None, orgs)
    } else {
        let (headers, orgs) = api.org_get_all().page(page).await?;
        (Some(headers.x_total_count.unwrap_or_default() as u64), orgs)
    };

    if orgs.is_empty() {
        println!("No results");
    } else {
        let SpecialRender {
            bullet,
            bold,
            reset,
            ..
        } = *crate::special_render();
        for org in orgs {
            let name = org.name.ok_or_eyre("org does not have name")?;
            println!("{bullet} {bold}{name}{reset}");
        }
        if let Some(total) = total {
            println!("Page {} of {}", page, total.div_ceil(20));
        }
    }
    Ok(())
}

async fn view_org(api: &Forgejo, name: String) -> eyre::Result<()> {
    let org = api.org_get(&name).await?;

    let SpecialRender {
        bold,
        dash,
        bright_cyan,
        light_grey,
        reset,
        ..
    } = *crate::special_render();

    let name = org.name.as_deref().ok_or_eyre("org does not have name")?;
    let visibility = org
        .visibility
        .as_deref()
        .ok_or_eyre("new org does not have visibility")?;
    let vis_pretty = match visibility {
        "public" => "Public",
        "limited" => "Limited",
        "private" => "Private",
        _ => visibility,
    };

    if let Some(full_name) = &org.full_name {
        print!("{bold}{bright_cyan}{full_name}{reset} {light_grey}({name}){reset}");
    } else {
        print!("{bold}{bright_cyan}{name}{reset}");
    }
    print!(" {dash} {vis_pretty}");
    println!();
    let member_count = match api.org_list_members(&name).page(1).page_size(1).await {
        Ok((members_headers, _)) => members_headers.x_total_count.unwrap_or_default(),
        Err(_) => {
            let (members_headers, _) = api
                .org_list_public_members(&name)
                .page(1)
                .page_size(1)
                .await?;
            members_headers.x_total_count.unwrap_or_default()
        }
    };
    print!("{bold}{member_count}{reset} members");
    if let Ok((teams_headers, _)) = api.org_list_teams(&name).page(1).page_size(1).await {
        let teams = teams_headers.x_total_count.unwrap_or_default();
        println!(" {dash} {bold}{teams}{reset} teams");
    }
    println!();

    let mut first = true;
    if let Some(website) = &org.website {
        if !website.is_empty() {
            print!("{bold}{website}{reset}");
            first = false;
        }
    }
    if let Some(email) = &org.email {
        if !email.is_empty() {
            if !first {
                print!(" {dash} ");
            }
            print!("{email}");
            first = false;
        }
    }
    if let Some(location) = &org.location {
        if !location.is_empty() {
            if !first {
                print!(" {dash} ");
            }
            print!("{location}");
            first = false;
        }
    }
    if !first {
        println!();
    }

    if let Some(description) = &org.description {
        if !description.is_empty() {
            println!("\n{}\n", crate::markdown(&description));
        }
    }

    Ok(())
}

async fn create_org(api: &Forgejo, name: String, options: OrgOptions) -> eyre::Result<()> {
    if !name.chars().all(is_valid_name_char) {
        eyre::bail!("Organization names can only have alphanumeric characters, dash, underscore, or period. \n  If you want a name with other characters, try setting the --full-name flag");
    }
    if !name
        .chars()
        .next()
        .is_some_and(|c| c.is_ascii_alphanumeric())
    {
        eyre::bail!("Organization names can only start with alphanumeric characters. \n  If you want a name that starts with other characters, try setting the --full-name flag");
    }
    if !name
        .chars()
        .last()
        .is_some_and(|c| c.is_ascii_alphanumeric())
    {
        eyre::bail!("Organization names can only end with alphanumeric characters. \n  If you want a name that ends with other characters, try setting the --full-name flag");
    }
    let mut chars = name.chars().peekable();
    while let Some(c) = chars.next() {
        // because of the prior check, if it isn't alphanumeric, it's definitely one of - _ or .
        if !c.is_alphanumeric() && !chars.peek().is_some_and(|c| c.is_alphanumeric()) {
            eyre::bail!("Organization names can't have consecutive non-alphanumberic characters.\n  If you want that in the name, try setting the --full-name flag");
        }
    }
    let opt = CreateOrgOption {
        description: options.description,
        email: options.email,
        full_name: options.full_name,
        location: options.location,
        repo_admin_change_team_access: options.admin_can_change_team_access,
        username: name,
        visibility: options.visibility.map(|v| v.into()),
        website: options.website,
    };
    let new_org = api.org_create(opt).await?;

    let name = new_org.name.ok_or_eyre("new org does not have name")?;
    let visibility = new_org
        .visibility
        .ok_or_eyre("new org does not have visibility")?;

    let SpecialRender {
        fancy,
        bold,
        light_grey,
        reset,
        ..
    } = *crate::special_render();
    print!("created new {visibility} org ");
    if let Some(full_name) = &new_org.full_name {
        if fancy {
            println!("{bold}{full_name}{reset} {light_grey}({name}){reset}");
        } else {
            println!("\"{full_name}\" ({name})");
        }
    } else {
        if fancy {
            println!("{bold}{name}{reset}");
        } else {
            println!("\"{name}\"");
        }
    }
    Ok(())
}

async fn edit_org(api: &Forgejo, name: String, options: OrgOptions) -> eyre::Result<()> {
    let opt = EditOrgOption {
        description: options.description,
        email: options.email,
        full_name: options.full_name,
        location: options.location,
        repo_admin_change_team_access: options.admin_can_change_team_access,
        visibility: options.visibility.map(|v| v.into()),
        website: options.website,
    };
    api.org_edit(&name, opt).await?;
    Ok(())
}

async fn list_activity(api: &Forgejo, name: String) -> eyre::Result<()> {
    let query = forgejo_api::structs::OrgListActivityFeedsQuery::default();
    let (_, feed) = api.org_list_activity_feeds(&name, query).await?;

    for activity in feed {
        crate::user::print_activity(&activity)?;
    }
    Ok(())
}

async fn list_org_members(api: &Forgejo, org: String, page: u32) -> eyre::Result<()> {
    let my_username = api
        .user_get_current()
        .await?
        .login
        .ok_or_eyre("current user does not have username")?;
    let (count, users) = if api.org_is_member(&org, &my_username).await.is_ok() {
        let (headers, users) = api.org_list_members(&org).page(page).await?;
        (headers.x_total_count.unwrap_or_default() as u64, users)
    } else {
        let (headers, users) = api.org_list_public_members(&org).page(page).await?;
        (headers.x_total_count.unwrap_or_default() as u64, users)
    };

    let SpecialRender {
        bullet,
        light_grey,
        bright_cyan,
        reset,
        ..
    } = crate::special_render();
    if users.is_empty() {
        println!("No results");
    } else {
        for user in users {
            let username = user
                .login
                .as_deref()
                .ok_or_eyre("repo does not have full name")?;
            match user.full_name.as_deref().filter(|s| !s.is_empty()) {
                Some(full_name) => println!(
                    "{bullet} {bright_cyan}{full_name}{reset} {light_grey}({username}){reset}"
                ),
                None => println!("{bullet} {bright_cyan}{username}{reset}"),
            }
        }
        println!("Page {} of {}", page, count.div_ceil(20));
    }
    Ok(())
}

async fn member_visibility(
    api: &Forgejo,
    org: String,
    visibility: Option<OrgMemberVisibility>,
) -> eyre::Result<()> {
    let username = api
        .user_get_current()
        .await?
        .login
        .ok_or_eyre("current user does not have username")?;
    let SpecialRender {
        bright_blue, reset, ..
    } = crate::special_render();
    if api.org_is_member(&org, &username).await.is_ok() {
        match visibility {
            Some(OrgMemberVisibility::Private) => {
                api.org_conceal_member(&org, &username).await?;
                println!("You are now a private member of {bright_blue}{org}{reset}");
            }
            Some(OrgMemberVisibility::Public) => {
                api.org_conceal_member(&org, &username).await?;
                println!("You are now a public member of {bright_blue}{org}{reset}");
            }
            None => {
                if api.org_is_public_member(&org, &username).await.is_ok() {
                    println!("You are a public member of {bright_blue}{org}{reset}");
                } else {
                    println!("You are a private member of {bright_blue}{org}{reset}");
                }
            }
        }
    } else {
        println!("You are not a member of {bright_blue}{org}{reset}");
    }
    Ok(())
}

#[derive(Subcommand, Clone, Debug)]
pub enum LabelSubcommand {
    /// List all the issue labels an organization uses.
    List {
        /// The name of the organization to list the labels of.
        org: String,
    },
    /// Add a new issue label to an organization.
    Add {
        /// The name of the organization the label should be added to.
        org: String,
        /// The name of the label to add.
        name: String,
        /// The hexcode of the label to add.
        color: String,
        /// A description of what the label is for.
        #[clap(long, short)]
        description: Option<String>,
        /// If this label is named `{scope}/{name}`, make it exclusive with other labels with the
        /// same scope.
        #[clap(long, short)]
        exclusive: bool,
    },
    /// Edit an issue label an organization uses.
    Edit {
        /// The name of the organization the label is in.
        org: String,
        /// The name of the label to edit.
        name: String,
        /// Set a new name for the label.
        #[clap(long, short)]
        new_name: Option<String>,
        /// Set a new hexcode for the label.
        #[clap(long, short)]
        color: Option<String>,
        /// Set a description of what the label is for.
        #[clap(long, short)]
        description: Option<String>,
        /// Set whether this label is exclusive with others of the same scope.
        #[clap(long, short)]
        exclusive: bool,
        /// Set whether this label is archived.
        #[clap(long, short)]
        archived: Option<bool>,
    },
    /// Remove an issue label from an organization.
    Rm {
        /// The name of the organization the label is in.
        org: String,
        /// The name of the label to remove from the organization.
        label: String,
    },
}

impl LabelSubcommand {
    async fn run(self, api: &Forgejo) -> eyre::Result<()> {
        match self {
            LabelSubcommand::List { org } => list_org_labels(&api, org).await?,
            LabelSubcommand::Add {
                org,
                name,
                color,
                description,
                exclusive,
            } => add_org_label(&api, org, name, color, description, exclusive).await?,
            LabelSubcommand::Edit {
                org,
                name,
                new_name,
                color,
                description,
                exclusive,
                archived,
            } => {
                edit_org_label(
                    &api,
                    org,
                    name,
                    new_name,
                    color,
                    description,
                    exclusive,
                    archived,
                )
                .await?
            }
            LabelSubcommand::Rm { org, label } => remove_org_label(&api, org, label).await?,
        }
        Ok(())
    }
}

async fn list_org_labels(api: &Forgejo, org: String) -> eyre::Result<()> {
    let labels = api
        .org_list_labels(&org, OrgListLabelsQuery::default())
        .all()
        .await?;
    crate::prs::render_label_list(&labels)?;
    Ok(())
}

async fn find_label_by_name(
    api: &Forgejo,
    org: &str,
    name: &str,
) -> eyre::Result<Option<forgejo_api::structs::Label>> {
    Ok(api
        .org_list_labels(&org, OrgListLabelsQuery::default())
        .stream()
        .try_filter(|label| {
            future::ready(
                label
                    .name
                    .as_deref()
                    .is_some_and(|label_name| label_name == name),
            )
        })
        .try_next()
        .await?)
}

async fn add_org_label(
    api: &Forgejo,
    org: String,
    name: String,
    color: String,
    description: Option<String>,
    exclusive: bool,
) -> eyre::Result<()> {
    let color = color
        .strip_prefix("#")
        .map(|s| s.to_owned())
        .unwrap_or(color);
    let opt = CreateLabelOption {
        color,
        description,
        exclusive: Some(exclusive),
        is_archived: Some(false),
        name,
    };
    let label = api.org_create_label(&org, opt).await?;
    println!("Created new label {}", crate::prs::render_label(&label)?);
    Ok(())
}

async fn edit_org_label(
    api: &Forgejo,
    org: String,
    name: String,
    new_name: Option<String>,
    color: Option<String>,
    description: Option<String>,
    exclusive: bool,
    archived: Option<bool>,
) -> eyre::Result<()> {
    let old_label = find_label_by_name(api, &org, &name)
        .await?
        .ok_or_eyre("label not found")?;
    let id = old_label.id.ok_or_eyre("label does not have id")?;
    let color = color.map(|color| {
        color
            .strip_prefix("#")
            .map(|s| s.to_owned())
            .unwrap_or(color)
    });
    let opt = EditLabelOption {
        color,
        description,
        exclusive: Some(exclusive),
        is_archived: archived,
        name: new_name,
    };
    let label = api.org_edit_label(&org, id, opt).await?;
    println!(
        "Changed label {} to {}",
        crate::prs::render_label(&old_label)?,
        crate::prs::render_label(&label)?
    );
    Ok(())
}

async fn remove_org_label(api: &Forgejo, org: String, name: String) -> eyre::Result<()> {
    let label = find_label_by_name(api, &org, &name)
        .await?
        .ok_or_eyre("label not found")?;
    let id = label.id.ok_or_eyre("label does not have id")?;
    api.org_delete_label(&org, id).await?;
    println!("Removed label {}", crate::prs::render_label(&label)?);
    Ok(())
}

#[derive(Subcommand, Clone, Debug)]
pub enum RepoSubcommand {
    /// List all the repos owned by this organization.
    List {
        /// The name of the organization to list the repos of.
        org: String,
        /// Which page of the results to view
        #[clap(long, short, default_value_t = 1)]
        page: u32,
    },
    /// Create a new repository in this organization.
    Create {
        /// The name of the organization to create the repo in.
        org: String,
        #[clap(flatten)]
        args: crate::repo::RepoCreateArgs,
    },
}

impl RepoSubcommand {
    async fn run(
        self,
        keys: &crate::KeyInfo,
        repo_info: &RepoInfo,
        api: &Forgejo,
    ) -> eyre::Result<()> {
        match self {
            RepoSubcommand::List { org, page } => list_org_repos(&api, org, page).await?,
            RepoSubcommand::Create {
                org,
                args:
                    crate::repo::RepoCreateArgs {
                        repo,
                        description,
                        private,
                        remote,
                        push,
                        ssh,
                    },
            } => {
                let url_host = crate::host_name(&repo_info.host_url());
                let ssh = ssh
                    .unwrap_or_else(|| Some(keys.default_ssh.contains(url_host)))
                    .unwrap_or(true);
                crate::repo::create_repo(
                    &api,
                    Some(org),
                    repo,
                    description,
                    private,
                    remote,
                    push,
                    ssh,
                )
                .await?
            }
        }
        Ok(())
    }
}

async fn list_org_repos(api: &Forgejo, org: String, page: u32) -> eyre::Result<()> {
    let (headers, repos) = api.org_list_repos(&org).page(page).await?;
    let SpecialRender { bullet, .. } = crate::special_render();
    if repos.is_empty() {
        println!("No results");
    } else {
        for repo in repos {
            let full_name = repo
                .full_name
                .as_deref()
                .ok_or_eyre("repo does not have full name")?;
            println!("{bullet} {full_name}");
        }
        let count = headers.x_total_count.unwrap_or_default() as u64;
        println!("Page {} of {}", page, count.div_ceil(20));
    }
    Ok(())
}