2022-10-31 21:05:47 +00:00
|
|
|
//! Miscellaneous utilities.
|
|
|
|
|
2022-11-28 21:48:35 +00:00
|
|
|
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")
|
|
|
|
}
|
2022-11-28 21:48:35 +00:00
|
|
|
|
|
|
|
/// 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 {
|
2024-01-17 17:10:25 +00:00
|
|
|
builder.add(Glob::new(glob)?);
|
2022-11-28 21:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.build().map_err(Into::into)
|
|
|
|
}
|