improve formatting of 'show'

This commit is contained in:
Dr. Matthias Ratajczak
2023-02-02 15:25:45 +01:00
parent 7ebd3a6c43
commit b9632ee8c2
3 changed files with 18 additions and 2 deletions
+12
View File
@@ -188,12 +188,24 @@ impl Pacdef {
fn show_group_content(&self, groups: &ArgMatches) -> Result<()> { fn show_group_content(&self, groups: &ArgMatches) -> Result<()> {
let mut iter = groups.get_many::<String>("group").unwrap().peekable(); let mut iter = groups.get_many::<String>("group").unwrap().peekable();
let show_more_than_one_group = iter.size_hint().0 > 1;
while let Some(arg_group) = iter.next() { while let Some(arg_group) = iter.next() {
let group = self let group = self
.groups .groups
.iter() .iter()
.find(|g| g.name == *arg_group) .find(|g| g.name == *arg_group)
.ok_or_else(|| anyhow!("group {} not found", *arg_group))?; .ok_or_else(|| anyhow!("group {} not found", *arg_group))?;
if show_more_than_one_group {
let name = &group.name;
println!("{name}");
for _ in 0..name.len() {
print!("-");
}
println!();
}
println!("{group}"); println!("{group}");
if iter.peek().is_some() { if iter.peek().is_some() {
println!(); println!();
+1 -1
View File
@@ -136,7 +136,7 @@ impl Display for Group {
while let Some(section) = iter.next() { while let Some(section) = iter.next() {
section.fmt(f)?; section.fmt(f)?;
if iter.peek().is_some() { if iter.peek().is_some() {
f.write_char('\n')?; f.write_str("\n\n")?;
} }
} }
Ok(()) Ok(())
+5 -1
View File
@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::iter::Peekable; use std::iter::Peekable;
use std::vec::IntoIter; use std::vec::IntoIter;
use anyhow::{Context, Result}; use anyhow::{bail, Context, Result};
use clap::ArgMatches; use clap::ArgMatches;
use regex::Regex; use regex::Regex;
@@ -27,6 +27,10 @@ pub(crate) fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Res
} }
} }
if vec.is_empty() {
bail!("no packages matching query")
}
print_triples(vec); print_triples(vec);
Ok(()) Ok(())