uucore: add crate_version macro

This commit is contained in:
Daniel Hofstetter 2025-03-15 15:04:45 +01:00
parent e147063e26
commit 12ab9c2c21
2 changed files with 22 additions and 0 deletions

View file

@ -1,2 +1,5 @@
[target.x86_64-unknown-redox]
linker = "x86_64-unknown-redox-gcc"
[env]
PROJECT_NAME_FOR_VERSION_STRING = "uutils coreutils"

View file

@ -165,6 +165,25 @@ macro_rules! bin {
};
}
/// Generate the version string for clap.
///
/// The generated string has the format `(<project name>) <version>`, 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 = "<project name>"` 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