5 Commits

Author SHA1 Message Date
d4ef21e243 Change to free-fn intersperse for stdlib compat
Itertools warns that the standard library may be stabilizing the
intersperse method soon and recommends using this function instead.
2025-07-02 22:44:06 -05:00
d94c350cde Galaxy-brained newline intersperse function
Itertools already has an intersperse method for me. Why would I build my
own when I can do this? There's even a `fold()` over the units that come
out of the print routine.
2025-07-02 22:29:07 -05:00
8120cb0489 Remove trailing newline in Release item printout 2025-07-02 22:08:45 -05:00
b82cfdb822 Colorize the output! 2025-07-02 22:06:36 -05:00
ea046c929f Print releases in reverse order for easier reading
The result list has the newest item first, but I want to print them the
other way around. This way the newest (and presumably most interesting)
release is always the visible item, regardless of how many others have
printed and scrolled off screen.
2025-07-02 21:42:41 -05:00
3 changed files with 29 additions and 12 deletions

View File

@@ -5,6 +5,8 @@ edition = "2024"
[dependencies]
clap = { version = "4.0.7", features = ["derive", "env"] }
colored = "2.0.0"
itertools = "0.10.0"
reqwest = { version = "0.11.13", features = ["json", "stream", "multipart"] }
serde = { version = "1.0.152", features = ["derive"] }
tokio = { version = "1.24.2", features = ["macros", "rt-multi-thread"] }

View File

@@ -33,9 +33,18 @@ async fn main() -> Result<(), gt_tool::Error> {
gt_tool::cli::Commands::ListReleases => {
let releases =
gt_tool::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
for release in releases {
println!("{}", release);
}
// Print in reverse order so the newest items are closest to the
// user's command prompt. Otherwise the newest item scrolls off the
// screen and can't be seen.
let _ = itertools::Itertools::intersperse(
releases
.iter()
.rev()
.map(|release| release.to_string()),
String::from("")
)
.map(|release| println!("{}", release))
.fold((), |_, _| () );
}
gt_tool::cli::Commands::CreateRelease {
name,

View File

@@ -1,5 +1,6 @@
use std::fmt::Display;
use colored::Colorize;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
@@ -23,23 +24,28 @@ pub struct Release {
impl Display for Release {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let tag = "Tag:".green().bold();
let name = "Name:".green();
let published = "Published:".bright_green();
let created = "Created:".green().dimmed();
let author = "Author:".blue();
let body = if self.body.len() > 0 {
&self.body
&self.body.white()
} else {
&String::from("(empty body)")
&String::from("(empty body)").dimmed()
};
write!(f,
"Tag: {}
Name: {}
"{tag} {}
{name} {}
{}
Published: {} (created: {})
Author: {} ({})
",
self.tag_name,
{published} {} ({created} {})
{author} {} ({})",
self.tag_name.bold(),
self.name,
body,
self.published_at,
self.created_at,
self.created_at.dimmed(),
self.author.login,
self.author.email,
)