Pluralize words correctly.
This commit is contained in:
parent
4f28ced1b1
commit
d4f22fb0c5
|
@ -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 {
|
||||
|
|
|
@ -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()?;
|
||||
|
|
|
@ -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")
|
||||
}
|
Loading…
Reference in New Issue