feat: Case insensitive filter #61

Merged
awiteb merged 1 commit from awiteb/fix-55 into master 2024-06-29 12:02:39 +02:00 AGit

View file

@ -47,23 +47,30 @@ impl LprsCommand for List {
)); ));
} }
let pattern = if self.regex || self.filter.is_none() { let pattern = if self.regex {
self.filter.unwrap_or_else(|| ".".to_owned()) self.filter
.expect("Is required if the `regex` option is `true`")
} else { } else {
format!( format!(
".*{}.*", ".*{}.*",
regex::escape(self.filter.as_deref().unwrap_or("")) regex::escape(self.filter.as_deref().unwrap_or_default())
) )
}; };
log::debug!("Listing vaults filtered by: {pattern}"); log::debug!("Listing vaults filtered by: {pattern}");
let re = regex::Regex::new(&pattern)?; let re = regex::Regex::new(&pattern.to_lowercase())?;
let vaults_list = vault_manager.vaults.iter().enumerate().filter(|(_, v)| { let vaults_list = vault_manager.vaults.iter().enumerate().filter(|(_, v)| {
re.is_match(&v.name) re.is_match(&v.name.to_lowercase())
|| v.username.as_deref().is_some_and(|u| re.is_match(u)) || v.username
|| v.service.as_deref().is_some_and(|s| re.is_match(s)) .as_deref()
|| v.note.as_deref().is_some_and(|n| re.is_match(n)) .is_some_and(|u| re.is_match(&u.to_lowercase()))
|| v.service
.as_deref()
.is_some_and(|s| re.is_match(&s.to_lowercase()))
|| v.note
.as_deref()
.is_some_and(|n| re.is_match(&n.to_lowercase()))
}); });
if self.json { if self.json {