diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 52d16b4..0e9ba32 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -5,33 +5,43 @@ use shared::{errors::Error, names::Site}; use crate::arguments::PrintGroup; -pub(crate) fn print(path: &Path, group: &PrintGroup, seperator: &Option) -> Result<(), Error> { +fn group_printing(seperator: &Option, 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, +) -> Result<(), Error> { let names_file = names::read_names_file(path)?; let names = names::load_names(names_file)?; - Ok(for site in names { + for site in names { if !group.url && !group.name { log::info!("{:?}", site); continue; } - let mut string = String::new(); - let delimiter = seperator.unwrap_or(','); + group_printing(seperator, site, group); + } - 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); - }) + Ok(()) } pub(crate) fn add(path: &Path, url: &String, name: &Option) -> Result<(), Error> {