feat(cli): enhance --version output with component versions

This commit is contained in:
Nils Andreas Svee committed 2026-10-21 14:42:49 +07:00
1 parent 7d640793b6
commit 5481009fe3
9 files changed
+61 -14

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ doc = false
[features] [features]
default = ["client", "server", "tui"] default = ["client", "server", "tui"]
client = ["dep:humantime", "dep:tokio", "dep:irtt-client", "irtt-client/ancillary", "irtt-client/tokio", "dep:irtt-proto", "dep:irtt-stats"] client = ["dep:humantime", "dep:tokio", "dep:irtt-client", "irtt-client/ancillary", "irtt-client/tokio", "dep:irtt-proto", "dep:irtt-stats"]
server = ["dep:irtt-server", "dep:tokio"] server = ["dep:irtt-server", "dep:irtt-proto", "dep:tokio"]
tui =["dep:humantime", "dep:tokio", "dep:futures-core", "dep:irtt-client", "irtt-client/ancillary", "irtt-client/tokio", "dep:irtt-proto", "dep:irtt-stats", "dep:ratatui", "dep:crossterm", "dep:chrono"] tui =["dep:humantime", "dep:tokio", "dep:futures-core", "dep:irtt-client", "irtt-client/ancillary", "irtt-client/tokio", "dep:irtt-proto", "dep:irtt-stats", "dep:ratatui", "dep:crossterm", "dep:chrono"]
[dependencies] [dependencies]
+1 -4
View File
@@ -55,10 +55,7 @@ pub fn dispatch_from_argv(argv: Vec<OsString>) -> Result<AppletDispatch, String>
}; };
match command { match command {
"-V" | "--version" => Ok(AppletDispatch::Help(format!( "-V" | "--version" => Ok(AppletDispatch::Help(crate::version::app())),
"irtt-rs {}",
env!("CARGO_PKG_VERSION")
))),
"-h" | "--help" => Ok(AppletDispatch::Help(dispatcher_help())), "-h" | "--help" => Ok(AppletDispatch::Help(dispatcher_help())),
"client" => Ok(AppletDispatch::Run { "client" => Ok(AppletDispatch::Run {
applet: RequestedApplet::Client, applet: RequestedApplet::Client,
+5 -9
View File
@@ -89,11 +89,10 @@ fn with_shutdown_flag(
#[cfg(feature = "client")] #[cfg(feature = "client")]
fn run_client_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> { fn run_client_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> {
use clap::Parser;
let shutdown = crate::signal::install_async_signal_handler() let shutdown = crate::signal::install_async_signal_handler()
.map_err(|err| format!("failed to install signal handler: {err}"))?; .map_err(|err| format!("failed to install signal handler: {err}"))?;
let args = crate::cmd::client::ClientArgs::parse_from(argv); let args =
crate::version::parse::<crate::cmd::client::ClientArgs>(argv, crate::version::client);
tokio::runtime::Builder::new_current_thread() tokio::runtime::Builder::new_current_thread()
.enable_all() .enable_all()
.build()? .build()?
@@ -107,10 +106,9 @@ fn run_client_applet(_argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Err
#[cfg(feature = "server")] #[cfg(feature = "server")]
fn run_server_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> { fn run_server_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> {
use clap::Parser;
with_shutdown_flag(|shutdown_requested| { with_shutdown_flag(|shutdown_requested| {
let args = crate::cmd::server::ServerArgs::parse_from(argv); let args =
crate::version::parse::<crate::cmd::server::ServerArgs>(argv, crate::version::server);
crate::cmd::server::run_server(args, shutdown_requested) crate::cmd::server::run_server(args, shutdown_requested)
}) })
} }
@@ -122,11 +120,9 @@ fn run_server_applet(_argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Err
#[cfg(feature = "tui")] #[cfg(feature = "tui")]
fn run_tui_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> { fn run_tui_applet(argv: Vec<OsString>) -> Result<(), Box<dyn std::error::Error>> {
use clap::Parser;
let shutdown = crate::signal::install_async_signal_handler() let shutdown = crate::signal::install_async_signal_handler()
.map_err(|err| format!("failed to install signal handler: {err}"))?; .map_err(|err| format!("failed to install signal handler: {err}"))?;
let args = crate::cmd::tui::TuiArgs::parse_from(argv); let args = crate::version::parse::<crate::cmd::tui::TuiArgs>(argv, crate::version::client);
tokio::runtime::Builder::new_current_thread() tokio::runtime::Builder::new_current_thread()
.enable_all() .enable_all()
.build()? .build()?
+2
View File
@@ -6,3 +6,5 @@ pub mod cmd;
pub mod entry; pub mod entry;
pub mod shared; pub mod shared;
pub mod signal; pub mod signal;
mod version;
+40
View File
@@ -0,0 +1,40 @@
#[cfg(any(feature = "client", feature = "tui", feature = "server"))]
use std::ffi::OsString;
pub(crate) fn app() -> String {
clap::Command::new("irtt-rs")
.version(env!("CARGO_PKG_VERSION"))
.render_version()
}
// Preserve Clap's version banner and append the compiled component versions.
#[cfg(any(feature = "client", feature = "tui", feature = "server"))]
pub(crate) fn parse<T: clap::Parser>(argv: Vec<OsString>, report: fn() -> String) -> T {
match T::try_parse_from(argv) {
Ok(args) => args,
Err(err) if err.kind() == clap::error::ErrorKind::DisplayVersion => {
print!("{}{}", err.render().ansi(), report());
std::process::exit(0)
}
Err(err) => err.exit(),
}
}
#[cfg(any(feature = "client", feature = "tui"))]
pub(crate) fn client() -> String {
format!(
" client: {}\n stats: {}\n proto: {}\n",
irtt_client::VERSION,
irtt_stats::VERSION,
irtt_proto::VERSION,
)
}
#[cfg(feature = "server")]
pub(crate) fn server() -> String {
format!(
" server: {}\n proto: {}\n",
irtt_server::VERSION,
irtt_proto::VERSION,
)
}
+3
View File
@@ -47,6 +47,9 @@
//! //!
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
/// Cargo package version of this compiled library.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(feature = "tokio")] #[cfg(feature = "tokio")]
mod async_client; mod async_client;
mod auth; mod auth;
+3
View File
@@ -77,6 +77,9 @@
//! //!
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
/// Cargo package version of this compiled library.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub mod echo; pub mod echo;
mod envelope; mod envelope;
pub mod error; pub mod error;
+3
View File
@@ -108,6 +108,9 @@
//! payload bytes never reach a reply under any mode. //! payload bytes never reach a reply under any mode.
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
/// Cargo package version of this compiled library.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
mod clock; mod clock;
mod config; mod config;
mod core; mod core;
+3
View File
@@ -25,6 +25,9 @@
#![warn(missing_docs)] #![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)] #![warn(rustdoc::missing_crate_level_docs)]
/// Cargo package version of this compiled library.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
use std::time::Duration; use std::time::Duration;
use irtt_client::ClientEvent; use irtt_client::ClientEvent;