From d71172542cdab4df02cab21b880eed7178f74c72 Mon Sep 17 00:00:00 2001 From: Michel de Graaf Date: Mon, 21 Sep 2026 12:15:43 +0200 Subject: [PATCH] feat(cli): let a build name its own version A nightly printed the same 19.0.0 as the release it followed, so a bug report could not say which one it came from. SOULSEEK_RS_VERSION at compile time replaces the crate version in --version, the TUI and the daemon status. --- soulseek-rs/src/cli.rs | 7 ++++++- soulseek-rs/src/daemon/server/mod.rs | 4 ++-- soulseek-rs/src/ui/downloads.rs | 3 +-- soulseek-rs/src/ui/panes/results_pane.rs | 3 +-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/soulseek-rs/src/cli.rs b/soulseek-rs/src/cli.rs index 8c5efd0..196a3c3 100644 --- a/soulseek-rs/src/cli.rs +++ b/soulseek-rs/src/cli.rs @@ -34,11 +34,16 @@ Exit codes: 0 success 2 usage/config 3 connect or login 4 no results 5 timed out 6 transfer failed 7 session lost 1 unexpected error"; +pub const VERSION: &str = match option_env!("SOULSEEK_RS_VERSION") { + Some(version) => version, + None => env!("CARGO_PKG_VERSION"), +}; + #[derive(Parser, Debug, Default)] #[command( name = "soulseek-rs", author, - version, + version = VERSION, about = "Soulseek client in Rust 🦀", long_about = "Soulseek client in Rust.\n\nRun without a subcommand for the \ interactive TUI, or use a subcommand for a scriptable \ diff --git a/soulseek-rs/src/daemon/server/mod.rs b/soulseek-rs/src/daemon/server/mod.rs index ca7fe3c..201a6d0 100644 --- a/soulseek-rs/src/daemon/server/mod.rs +++ b/soulseek-rs/src/daemon/server/mod.rs @@ -522,7 +522,7 @@ impl Daemon { fn identify(&self) -> AuthResult { AuthResult { protocol: PROTOCOL_VERSION, - daemon_version: env!("CARGO_PKG_VERSION").to_string(), + daemon_version: crate::cli::VERSION.to_string(), username: self.session.username(), } } @@ -532,7 +532,7 @@ impl Daemon { DaemonStatus { username: self.session.username(), server: self.server.clone(), - daemon_version: env!("CARGO_PKG_VERSION").to_string(), + daemon_version: crate::cli::VERSION.to_string(), protocol: PROTOCOL_VERSION, listen_port: self.session.listen_port(), shared_folders: folders, diff --git a/soulseek-rs/src/ui/downloads.rs b/soulseek-rs/src/ui/downloads.rs index f79f718..24eec71 100644 --- a/soulseek-rs/src/ui/downloads.rs +++ b/soulseek-rs/src/ui/downloads.rs @@ -1,3 +1,4 @@ +use crate::cli::VERSION; use crate::models::DownloadEntry; use crate::ui::{ BYTES_PER_MB, accent_style, dimmed_style, error_style, @@ -14,8 +15,6 @@ use ratatui::{ use soulseek_rs::DownloadStatus; use std::fmt::Write as _; -const VERSION: &str = env!("CARGO_PKG_VERSION"); - /// Bytes transferred, bytes expected and combined speed across the downloads /// that are actually running — or `None` when none are, so the caller can hide /// the progress readout entirely. diff --git a/soulseek-rs/src/ui/panes/results_pane.rs b/soulseek-rs/src/ui/panes/results_pane.rs index 1b71f59..e111655 100644 --- a/soulseek-rs/src/ui/panes/results_pane.rs +++ b/soulseek-rs/src/ui/panes/results_pane.rs @@ -1,4 +1,5 @@ use super::name_scroll::{column_width, end_offset, scroll_text}; +use crate::cli::VERSION; use crate::models::FileDisplayData; use crate::ui::{ BYTES_PER_MB, HIGHLIGHT_SYMBOL, body_style, dimmed_style, format_bytes, @@ -13,8 +14,6 @@ use ratatui::{ }; use std::collections::HashSet; -const VERSION: &str = env!("CARGO_PKG_VERSION"); - // The file name and its folder share whatever width the fixed columns leave, // the name getting the larger part: it is what a search is after, and a // folder's tail is a scroll away.