move command group printing logic into function

this makes the print function a bit cleaner.
This commit is contained in:
Fries 2023-07-01 20:39:56 -07:00
parent 7f36560e25
commit e93b201d77

View file

@ -5,33 +5,43 @@ use shared::{errors::Error, names::Site};
use crate::arguments::PrintGroup; use crate::arguments::PrintGroup;
pub(crate) fn print(path: &Path, group: &PrintGroup, seperator: &Option<char>) -> Result<(), Error> { fn group_printing(seperator: &Option<char>, site: Site, group: &PrintGroup) {
let mut string = String::new();
let delimiter = seperator.unwrap_or(',');
if group.url {
string += &site.url;
}
if group.name {
if !string.is_empty() {
string += &format!("{}{}", delimiter, site.name.unwrap_or("None".to_string()))
} else {
string += &site.name.unwrap_or("None".to_string());
}
}
log::info!("{}", string);
}
pub(crate) fn print(
path: &Path,
group: &PrintGroup,
seperator: &Option<char>,
) -> Result<(), Error> {
let names_file = names::read_names_file(path)?; let names_file = names::read_names_file(path)?;
let names = names::load_names(names_file)?; let names = names::load_names(names_file)?;
Ok(for site in names { for site in names {
if !group.url && !group.name { if !group.url && !group.name {
log::info!("{:?}", site); log::info!("{:?}", site);
continue; continue;
} }
let mut string = String::new(); group_printing(seperator, site, group);
let delimiter = seperator.unwrap_or(','); }
if group.url { Ok(())
string += &site.url;
}
if group.name {
if !string.is_empty() {
string += &format!("{}{}", delimiter, site.name.unwrap_or("None".to_string()))
} else {
string += &site.name.unwrap_or("None".to_string());
}
}
log::info!("{}", string);
})
} }
pub(crate) fn add(path: &Path, url: &String, name: &Option<String>) -> Result<(), Error> { pub(crate) fn add(path: &Path, url: &String, name: &Option<String>) -> Result<(), Error> {