From 1e333dfb337bb0f6ca662f2ecf1ca012ce9c18ee Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 31 Mar 2020 14:54:45 -0700 Subject: [PATCH] Show commit hash in version number --- CHANGELOG.md | 4 ++++ build.rs | 14 ++++++++++++++ src/main.rs | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d37ff7..5cf95e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Version output displays `git` revision information. + ## [0.3.0] - 2020-03-30 ### Added diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..b9ae403 --- /dev/null +++ b/build.rs @@ -0,0 +1,14 @@ +fn main() { + let git_describe = std::process::Command::new("git") + .args(&["describe", "--tags", "--broken"]) + .output() + .ok() + .and_then(|proc| String::from_utf8(proc.stdout).ok()); + + let version_info = match git_describe { + Some(description) if !description.is_empty() => description, + _ => format!("v{}-unknown", env!("CARGO_PKG_VERSION")), + }; + + println!("cargo:rustc-env=ZOXIDE_VERSION={}", version_info); +} diff --git a/src/main.rs b/src/main.rs index a480b45..012f85c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use anyhow::Result; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "A cd command that learns your habits")] +#[structopt(about = "A cd command that learns your habits", version = env!("ZOXIDE_VERSION"))] enum Zoxide { Add(subcommand::Add), Import(subcommand::Import),