From 12ab9c2c210477a63004944729432a75af25784f Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sat, 15 Mar 2025 15:04:45 +0100 Subject: [PATCH] uucore: add crate_version macro --- .cargo/config.toml | 3 +++ src/uucore/src/lib/lib.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.cargo/config.toml b/.cargo/config.toml index 58e1381b1..c6aa20761 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ [target.x86_64-unknown-redox] linker = "x86_64-unknown-redox-gcc" + +[env] +PROJECT_NAME_FOR_VERSION_STRING = "uutils coreutils" diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index df51425e5..e6d98b695 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -165,6 +165,25 @@ macro_rules! bin { }; } +/// Generate the version string for clap. +/// +/// The generated string has the format `() `, for +/// example: "(uutils coreutils) 0.30.0". clap will then prefix it with the util name. +/// +/// To use this macro, you have to add `PROJECT_NAME_FOR_VERSION_STRING = ""` to the +/// `[env]` section in `.cargo/config.toml`. +#[macro_export] +macro_rules! crate_version { + () => { + concat!( + "(", + env!("PROJECT_NAME_FOR_VERSION_STRING"), + ") ", + env!("CARGO_PKG_VERSION") + ) + }; +} + /// Generate the usage string for clap. /// /// This function does two things. It indents all but the first line to align