add showing group content
This commit is contained in:
+6
-3
@@ -29,7 +29,9 @@ impl Pacdef {
|
||||
self.edit_group_files(groups).context("editing group files")
|
||||
}
|
||||
Some((action::GROUPS, _)) => Ok(self.show_groups()),
|
||||
Some((action::SHOW, _)) => Ok(self.show_packages_under_group()),
|
||||
Some((action::SHOW, groups)) => {
|
||||
self.show_group_content(groups).context("showing groups")
|
||||
}
|
||||
Some((action::SYNC, _)) => Ok(self.install_packages()),
|
||||
Some((action::UNMANAGED, _)) => Ok(self.show_unmanaged_packages()),
|
||||
Some((action::VERSION, _)) => Ok(self.show_version()),
|
||||
@@ -169,12 +171,13 @@ impl Pacdef {
|
||||
}
|
||||
}
|
||||
|
||||
fn show_packages_under_group(&self) {
|
||||
let groups = self.args.get_many::<String>("group").unwrap();
|
||||
fn show_group_content(&self, groups: &ArgMatches) -> Result<()> {
|
||||
let groups = groups.get_many::<String>("group").unwrap();
|
||||
for arg_group in groups {
|
||||
let group = self.groups.iter().find(|g| g.name == *arg_group).unwrap();
|
||||
println!("{group}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fs::read_to_string;
|
||||
use std::hash::Hash;
|
||||
use std::path::Path;
|
||||
use std::{collections::HashSet, fmt::Display};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
@@ -87,3 +87,15 @@ impl Group {
|
||||
Ok(Self { name, sections })
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Group {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut sections: Vec<_> = self.sections.iter().collect();
|
||||
sections.sort_unstable();
|
||||
|
||||
for section in sections {
|
||||
section.fmt(f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+38
-1
@@ -1,4 +1,9 @@
|
||||
use std::{collections::HashSet, hash::Hash, iter::Peekable};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fmt::{Display, Write},
|
||||
hash::Hash,
|
||||
iter::Peekable,
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
@@ -48,3 +53,35 @@ impl PartialEq for Section {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Section {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.name.partial_cmp(&other.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for Section {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Section {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("[{}]\n", &self.name))?;
|
||||
|
||||
let mut packages: Vec<_> = self.packages.iter().collect();
|
||||
packages.sort_unstable();
|
||||
|
||||
let mut iter = packages.iter().peekable();
|
||||
|
||||
while let Some(package) = iter.next() {
|
||||
package.fmt(f)?;
|
||||
if iter.peek().is_some() {
|
||||
f.write_char('\n')?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user