fix bug in show

This commit is contained in:
steven-omaha
2023-01-12 15:30:55 +01:00
parent f725afb475
commit 0b4b45ed73
2 changed files with 14 additions and 3 deletions
+7 -2
View File
@@ -170,11 +170,16 @@ impl Pacdef {
} }
fn show_group_content(&self, groups: &ArgMatches) -> Result<()> { fn show_group_content(&self, groups: &ArgMatches) -> Result<()> {
let groups = groups.get_many::<String>("group").unwrap(); let mut iter = groups.get_many::<String>("group").unwrap().peekable();
for arg_group in groups {
while let Some(arg_group) = iter.next() {
let group = self.groups.iter().find(|g| g.name == *arg_group).unwrap(); let group = self.groups.iter().find(|g| g.name == *arg_group).unwrap();
println!("{group}"); println!("{group}");
if iter.peek().is_some() {
println!();
}
} }
Ok(()) Ok(())
} }
+7 -1
View File
@@ -1,3 +1,4 @@
use std::fmt::Write;
use std::fs::read_to_string; use std::fs::read_to_string;
use std::hash::Hash; use std::hash::Hash;
use std::path::Path; use std::path::Path;
@@ -102,8 +103,13 @@ impl Display for Group {
let mut sections: Vec<_> = self.sections.iter().collect(); let mut sections: Vec<_> = self.sections.iter().collect();
sections.sort_unstable(); sections.sort_unstable();
for section in sections { let mut iter = sections.into_iter().peekable();
while let Some(section) = iter.next() {
section.fmt(f)?; section.fmt(f)?;
if iter.peek().is_some() {
f.write_char('\n')?;
}
} }
Ok(()) Ok(())
} }