hooked/hooked-cli/source/utilities/mod.rs

28 lines
644 B
Rust
Raw Permalink Normal View History

2022-10-31 21:05:47 +00:00
//! Miscellaneous utilities.
use color_eyre::Result;
use globset::{Glob, GlobSet, GlobSetBuilder};
2022-10-31 21:05:47 +00:00
/// Simple function to create a pluralized string.
pub fn plural(count: usize, singular: &str, plural: Option<&str>) -> String {
2022-11-01 11:27:01 +00:00
if count == 1 {
2022-10-31 21:05:47 +00:00
return singular.to_string();
}
if let Some(plural) = plural {
return plural.to_string();
}
format!("{singular}s")
}
/// Create a [`GlobSet`] from a list of strings.
pub fn globset_from_strings(input: &[String]) -> Result<GlobSet> {
let mut builder = GlobSetBuilder::new();
for glob in input {
builder.add(Glob::new(glob)?);
}
builder.build().map_err(Into::into)
}