allow including extra info in --version output

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
Charles Hall 2024-03-22 19:50:57 -04:00 committed by June
parent 9f7431c08f
commit 74c34e885e
3 changed files with 17 additions and 1 deletions

View file

@ -218,6 +218,7 @@ features = [
"help", "help",
"usage", "usage",
"error-context", "error-context",
"string"
] ]
[dependencies.futures-util] [dependencies.futures-util]

View file

@ -73,6 +73,7 @@
]; ];
env = pkgs: { env = pkgs: {
CONDUIT_VERSION_EXTRA = self.shortRev or self.dirtyShortRev;
ROCKSDB_INCLUDE_DIR = "${rocksdb' pkgs}/include"; ROCKSDB_INCLUDE_DIR = "${rocksdb' pkgs}/include";
ROCKSDB_LIB_DIR = "${rocksdb' pkgs}/lib"; ROCKSDB_LIB_DIR = "${rocksdb' pkgs}/lib";
} }

View file

@ -4,9 +4,23 @@ use std::path::PathBuf;
use clap::Parser; 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 /// Commandline arguments
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(version, about, long_about = None)] #[clap(version = version(), about, long_about = None)]
pub struct Args { pub struct Args {
#[arg(short, long)] #[arg(short, long)]
/// Optional argument to the path of a conduwuit config TOML file /// Optional argument to the path of a conduwuit config TOML file