feat: warn about missing group only when relevant

So far we have warned the user when we first visited the group dir and
there were no group files. This lead to spurious warnings, e.g. when the
user wanted to import or create a group. We now defer the check to when
we actually need some content in the groups, and the program should not
perform the respective action without any groups present. This causes
some code duplication, but enhances UE.

Closes #31.
This commit is contained in:
steven-omaha
2023-05-23 17:54:08 +02:00
parent 008892b7ce
commit 654be10518
3 changed files with 31 additions and 7 deletions
+5
View File
@@ -17,6 +17,11 @@ use crate::grouping::{Group, Package, Section};
/// - an invalid regex was provided, or
/// - no matching packages could be found.
pub fn search_packages(regex_str: &str, groups: &HashSet<Group>) -> Result<()> {
if groups.is_empty() {
eprintln!("WARNING: no group files found");
bail!(crate::errors::Error::NoPackagesFound);
}
let re = Regex::new(regex_str)?;
let mut vec = vec![];