diff --git a/Cargo.toml b/Cargo.toml index d6075dd7..d350438f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -218,6 +218,7 @@ features = [ "help", "usage", "error-context", + "string" ] [dependencies.futures-util] diff --git a/flake.nix b/flake.nix index 66b2598a..16ac7e5d 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,7 @@ ]; env = pkgs: { + CONDUIT_VERSION_EXTRA = self.shortRev or self.dirtyShortRev; ROCKSDB_INCLUDE_DIR = "${rocksdb' pkgs}/include"; ROCKSDB_LIB_DIR = "${rocksdb' pkgs}/lib"; } diff --git a/src/clap.rs b/src/clap.rs index 446398c7..f1748b71 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -4,9 +4,23 @@ use std::path::PathBuf; use clap::Parser; +/// Returns the current version of the crate with extra info if supplied +/// +/// Set the environment variable `CONDUIT_VERSION_EXTRA` to any UTF-8 string to +/// include it in parenthesis after the SemVer version. A common value are git +/// commit hashes. +fn version() -> String { + let cargo_pkg_version = env!("CARGO_PKG_VERSION"); + + match option_env!("CONDUIT_VERSION_EXTRA") { + Some(x) => format!("{} ({})", cargo_pkg_version, x), + None => cargo_pkg_version.to_owned(), + } +} + /// Commandline arguments #[derive(Parser, Debug)] -#[clap(version, about, long_about = None)] +#[clap(version = version(), about, long_about = None)] pub struct Args { #[arg(short, long)] /// Optional argument to the path of a conduwuit config TOML file