From 135acf09b757d9ff51d3873ff811362513b27526 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Wed, 2 Jul 2025 12:56:17 -0500 Subject: [PATCH] Basic impl Display for the Release struct I'm not certain what info I want to present when listing the Releases. The idea is that the release version is the most important, and that it matches the git-tag associated with the release. I'll print that first. Next, the name of the release followed by the body text. The list of releases will become quite large for some projects, and the body text may include a changelog. Both of these will cause the output to become quite large. I will need to create a size limiter, but I'm ignoring that for now. Who created the release and when may be useful when searching for a release, so I've included that as the final section. --- src/main.rs | 2 +- src/structs/release.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 555b843..67c6241 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ async fn main() -> Result<(), gt_tool::Error> { let releases = gt_tool::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?; for release in releases { - println!("{:?}", release); + println!("{}", release); } } gt_tool::cli::Commands::CreateRelease { diff --git a/src/structs/release.rs b/src/structs/release.rs index 1f8a33b..e065d5a 100644 --- a/src/structs/release.rs +++ b/src/structs/release.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] @@ -19,6 +21,31 @@ pub struct Release { author: Author, } +impl Display for Release { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let body = if self.body.len() > 0 { + &self.body + } else { + &String::from("(empty body)") + }; + write!(f, +"Tag: {} +Name: {} + {} +Published: {} (created: {}) +Author: {} ({}) +", + self.tag_name, + self.name, + body, + self.published_at, + self.created_at, + self.author.login, + self.author.email, + ) + } +} + #[derive(Debug, Deserialize, Serialize)] pub struct Author { id: usize,