chore: Move repo::view::format_list to utils::format_iter
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -14,8 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// 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>.
|
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use nostr::nips::nip19::ToBech32;
|
use nostr::nips::nip19::ToBech32;
|
||||||
|
|
||||||
@@ -68,13 +66,16 @@ impl CommandRunner for ViewArgs {
|
|||||||
repo_details.push_str(&format!("\nDescription: {desc}"));
|
repo_details.push_str(&format!("\nDescription: {desc}"));
|
||||||
}
|
}
|
||||||
if !repo.web.is_empty() {
|
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() {
|
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() {
|
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 {
|
if let Some(euc) = repo.euc {
|
||||||
repo_details.push_str(&format!("\nEarliest unique commit: {euc}"));
|
repo_details.push_str(&format!("\nEarliest unique commit: {euc}"));
|
||||||
@@ -82,7 +83,7 @@ impl CommandRunner for ViewArgs {
|
|||||||
if !repo.maintainers.is_empty() {
|
if !repo.maintainers.is_empty() {
|
||||||
repo_details.push_str(&format!(
|
repo_details.push_str(&format!(
|
||||||
"\nMaintainers:\n{}",
|
"\nMaintainers:\n{}",
|
||||||
format_list(
|
utils::format_iter(
|
||||||
repo.maintainers
|
repo.maintainers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| p.to_bech32().expect("Infallible"))
|
.map(|p| p.to_bech32().expect("Infallible"))
|
||||||
@@ -96,16 +97,3 @@ impl CommandRunner for ViewArgs {
|
|||||||
Ok(())
|
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")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -338,3 +338,16 @@ pub fn subject_and_body(
|
|||||||
Ok((file_content.trim().to_owned(), None))
|
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")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user