docs(search): add docstrings
This commit is contained in:
@@ -8,12 +8,17 @@ use regex::Regex;
|
|||||||
|
|
||||||
use crate::grouping::{Group, Package, Section};
|
use crate::grouping::{Group, Package, Section};
|
||||||
|
|
||||||
|
/// Find all packages in all groups whose name match the regex from the
|
||||||
|
/// command-line arguments. Print the name of the packages per group and
|
||||||
|
/// section.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if
|
||||||
|
/// - an invalid regex was provided, or
|
||||||
|
/// - no matching packages could be found.
|
||||||
pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()> {
|
pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()> {
|
||||||
let search_string = args
|
let re = get_regex_from_args(args)?;
|
||||||
.get_one::<String>("regex")
|
|
||||||
.context("getting search string from arg")?;
|
|
||||||
|
|
||||||
let re = Regex::new(search_string)?;
|
|
||||||
|
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
|
|
||||||
@@ -36,6 +41,21 @@ pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract the user-provided regex from the command-line args.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if an invalid regex was provided.
|
||||||
|
fn get_regex_from_args(args: &ArgMatches) -> Result<Regex, anyhow::Error> {
|
||||||
|
let search_string = args
|
||||||
|
.get_one::<String>("regex")
|
||||||
|
.context("getting search string from arg")?;
|
||||||
|
|
||||||
|
let re = Regex::new(search_string)?;
|
||||||
|
|
||||||
|
Ok(re)
|
||||||
|
}
|
||||||
|
|
||||||
fn print_triples(mut vec: Vec<(&Group, &Section, &Package)>) {
|
fn print_triples(mut vec: Vec<(&Group, &Section, &Package)>) {
|
||||||
vec.sort_unstable();
|
vec.sort_unstable();
|
||||||
|
|
||||||
@@ -69,19 +89,23 @@ fn print_separator_unless_exhausted(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_section_if_changed(s: &Section, s0: &String) {
|
fn print_section_if_changed(current: &Section, previous_name: &String) {
|
||||||
if s.name != *s0 {
|
if current.name != *previous_name {
|
||||||
println!("[{}]", s.name);
|
println!("[{}]", current.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_group_if_changed(g: &Group, g0: &String, s0: &mut String) {
|
fn print_group_if_changed(
|
||||||
if g.name != *g0 {
|
current_group: &Group,
|
||||||
println!("{}", g.name);
|
previous_group_name: &String,
|
||||||
for _ in 0..g.name.len() {
|
previous_section_name: &mut String,
|
||||||
|
) {
|
||||||
|
if current_group.name != *previous_group_name {
|
||||||
|
println!("{}", current_group.name);
|
||||||
|
for _ in 0..current_group.name.len() {
|
||||||
print!("-");
|
print!("-");
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
s0.clear();
|
previous_section_name.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user