chore: Move repo::view::format_list to utils::format_iter

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-08-25 13:22:40 +00:00
parent 518e573467
commit f996fd351b
2 changed files with 20 additions and 19 deletions

View File

@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
use std::fmt;
use clap::Args;
use nostr::nips::nip19::ToBech32;
@@ -68,13 +66,16 @@ impl CommandRunner for ViewArgs {
repo_details.push_str(&format!("\nDescription: {desc}"));
}
if !repo.web.is_empty() {
repo_details.push_str(&format!("\nWebpages:\n{}", format_list(repo.web)));
repo_details.push_str(&format!("\nWebpages:\n{}", utils::format_iter(repo.web)));
}
if !repo.clone.is_empty() {
repo_details.push_str(&format!("\nClone urls:\n{}", format_list(repo.clone)));
repo_details.push_str(&format!(
"\nClone urls:\n{}",
utils::format_iter(repo.clone)
));
}
if !repo.relays.is_empty() {
repo_details.push_str(&format!("\nRelays:\n{}", format_list(repo.relays)));
repo_details.push_str(&format!("\nRelays:\n{}", utils::format_iter(repo.relays)));
}
if let Some(euc) = repo.euc {
repo_details.push_str(&format!("\nEarliest unique commit: {euc}"));
@@ -82,7 +83,7 @@ impl CommandRunner for ViewArgs {
if !repo.maintainers.is_empty() {
repo_details.push_str(&format!(
"\nMaintainers:\n{}",
format_list(
utils::format_iter(
repo.maintainers
.iter()
.map(|p| p.to_bech32().expect("Infallible"))
@@ -96,16 +97,3 @@ impl CommandRunner for ViewArgs {
Ok(())
}
}
/// Format a vector to print it
fn format_list<I, T>(iterator: I) -> String
where
I: IntoIterator<Item = T>,
T: fmt::Display,
{
iterator
.into_iter()
.map(|t| format!(" - {t}"))
.collect::<Vec<String>>()
.join("\n")
}

View File

@@ -338,3 +338,16 @@ pub fn subject_and_body(
Ok((file_content.trim().to_owned(), None))
}
}
/// Format an iterator to print it
pub fn format_iter<I, T>(iterator: I) -> String
where
I: IntoIterator<Item = T>,
T: fmt::Display,
{
iterator
.into_iter()
.map(|t| format!(" - {t}"))
.collect::<Vec<String>>()
.join("\n")
}