Pluralize words correctly.

This commit is contained in:
Bauke 2022-10-31 22:05:47 +01:00
parent 4f28ced1b1
commit d4f22fb0c5
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 21 additions and 2 deletions

View File

@ -10,6 +10,8 @@ use {
supports_color::Stream,
};
use crate::utilities::plural;
/// The `run` subcommand.
pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
let (success_style, warn_style, error_style) =
@ -25,9 +27,11 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
};
if hook_type == "pre-commit" {
let hook_count = config.pre_commit.len();
println!(
"Hooked: Running {} pre-commit hooks.",
config.pre_commit.len()
"Hooked: Running {} pre-commit {}.",
hook_count,
plural(hook_count, "hook", None)
);
for hook in config.pre_commit {

View File

@ -27,6 +27,7 @@ pub const DEFAULT_TEMPLATE: &str = include_str!("templates/default.sh");
pub const HOOK_TYPES: [&str; 1] = ["pre-commit"];
mod cli;
mod utilities;
fn main() -> Result<()> {
install()?;

View File

@ -0,0 +1,14 @@
//! Miscellaneous utilities.
/// Simple function to create a pluralized string.
pub fn plural(count: usize, singular: &str, plural: Option<&str>) -> String {
if count == 0 {
return singular.to_string();
}
if let Some(plural) = plural {
return plural.to_string();
}
format!("{singular}s")
}