Skip to content

Commit 270cc8f

Browse files
committed
replaced only_the_best option with max_mirrors_to_output
1 parent 6b331d6 commit 270cc8f

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.22.0 (2025-08-31)
2+
3+
- added option to limit number of mirrors to output [#78 by catap](https://github.com/westandskif/rate-mirrors/pull/78)
4+
5+
16
# 0.21.0 (2025-08-29)
27

38
- changed duration format in debug output [#76 by damentz](https://github.com/westandskif/rate-mirrors/pull/76)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rate_mirrors"
3-
version = "0.21.0"
3+
version = "0.22.0"
44
authors = ["Nikita Almakov <nikita.almakov@gmail.com>"]
55
edition = "2024"
66
description = "Everyday-use client-side map-aware mirror ranking tool (Arch Linux; Manjaro; custom ones)"

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ pub struct Config {
251251
)]
252252
pub top_mirrors_number_to_retest: usize,
253253

254-
/// Only one, the best mirror
255-
#[arg(env = "RATE_MIRRORS_ONLY_THE_BEST", long)]
256-
pub only_the_best: bool,
254+
/// Max number of mirrors to output
255+
#[arg(env = "RATE_MIRRORS_MAX_MIRRORS_TO_OUTPUT", long)]
256+
pub max_mirrors_to_output: Option<usize>,
257257

258258
/// Filename to save the output to in case of success
259259
#[arg(env = "RATE_MIRRORS_SAVE", long = "save", verbatim_doc_comment)]

src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod target_configs;
99
mod targets;
1010

1111
use crate::config::{AppError, Config, FetchMirrors};
12-
use crate::speed_test::{test_speed_by_countries, SpeedTestResults};
12+
use crate::speed_test::{test_speed_by_countries, SpeedTestResult, SpeedTestResults};
1313
use chrono::prelude::*;
1414
use clap::Parser;
1515
use config::LogFormatter;
@@ -93,10 +93,10 @@ impl<'a, T: LogFormatter> OutputSink<'a, T> {
9393

9494
fn main() -> Result<(), AppError> {
9595
let config = Arc::new(Config::parse());
96-
let only_the_best = config.only_the_best;
9796
if !config.allow_root && Uid::effective().is_root() {
9897
return Err(AppError::Root);
9998
}
99+
let max_mirrors_to_output = config.max_mirrors_to_output.clone();
100100

101101
let ref formatter = Arc::clone(&config).target;
102102
let mut output = OutputSink::new(
@@ -158,12 +158,13 @@ fn main() -> Result<(), AppError> {
158158

159159
output.display_comment(format!("FINISHED AT: {}", Local::now()));
160160

161-
if only_the_best {
162-
output.display_mirror(&results.first().unwrap().item);
163-
} else {
164-
for result in results.into_iter() {
165-
output.display_mirror(&result.item);
166-
}
161+
let it: Box<dyn Iterator<Item = SpeedTestResult>> = match max_mirrors_to_output {
162+
Some(n) => Box::new(results.into_iter().take(n)),
163+
None => Box::new(results.into_iter()),
164+
};
165+
166+
for result in it {
167+
output.display_mirror(&result.item);
167168
}
168169
}
169170

0 commit comments

Comments
 (0)