Skip to content

Commit 7215bd6

Browse files
committed
Add pluralization support
1 parent 9d39a51 commit 7215bd6

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/commands/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ fn apply_diff_and_print<TM: TimeMachineTrait>(
6464
let remove_count = diff.removed.len();
6565

6666
if add_count > 0 {
67-
info!("Added {add_count} paths to the backup exclusion list");
67+
info!("Added {add_count} {} to the backup exclusion list", crate::text::plural("path", add_count));
6868
}
6969

7070
if remove_count > 0 {
71-
info!("Removed {remove_count} paths from the backup exclusion list");
71+
info!("Removed {remove_count} {} from the backup exclusion list", crate::text::plural("path", remove_count));
7272
}
7373

7474
if add_count == 0 && remove_count == 0 {

src/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn execute(
3232
}
3333
thread_handle.join().unwrap();
3434

35-
info!("Found {} repositories", repositories.len());
35+
info!("Found {} {}", repositories.len(), crate::text::plural("repository", repositories.len()));
3636

3737
if details {
3838
for repository in &repositories {

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct ValidationError {
7575

7676
impl std::fmt::Display for ValidationError {
7777
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78-
writeln!(f, "Validation error:")?;
78+
writeln!(f, "{} failed:", crate::text::plural("validation", self.fails.len()))?;
7979
for fail in &self.fails {
8080
writeln!(f, " - {fail}")?;
8181
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod git;
88
mod json;
99
mod legacy_cache;
1010
mod legacy_config;
11+
mod text;
1112
mod timemachine;
1213

1314
use anyhow::anyhow;

src/text.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub fn plural(word: &str, count: usize) -> String {
2+
let mut word = word.to_string();
3+
if count == 0 || count > 1 {
4+
if word.ends_with('y') && word.len() > 1 {
5+
let _ = word.pop();
6+
word.push_str("ies");
7+
}
8+
else {
9+
word.push_str("s");
10+
}
11+
}
12+
word
13+
}

0 commit comments

Comments
 (0)