on master help sign in
Include git hash in `bat -V` and `bat --version` output if present
4081aceMartin Nordholts
CHANGELOG.md+1
@@ -20,6 +20,7 @@
20
20
21- Add PowerShell completion, see #1826 (@rashil2000)
21- Add PowerShell completion, see #1826 (@rashil2000)
22- Minimum supported Rust version (MSRV) bumped to 1.46
22- Minimum supported Rust version (MSRV) bumped to 1.46
23+- Include git hash in `bat -V` and `bat --version` output if present. See #1921 (@Enselic)
23
24
24## Syntaxes
25## Syntaxes
25
26
src/bin/bat/clap_app.rs+16−1
@@ -2,6 +2,21 @@ use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup
2use std::env;
2use std::env;
3use std::path::Path;
3use std::path::Path;
4
4
5+lazy_static::lazy_static! {
6+ static ref VERSION: String = {
7+ #[cfg(feature = "bugreport")]
8+ let git_version = bugreport::git_version!(fallback = "");
9+ #[cfg(not(feature = "bugreport"))]
10+ let git_version = "";
11+
12+ if git_version.is_empty() {
13+ crate_version!().to_string()
14+ } else {
15+ format!("{} ({})", crate_version!(), git_version)
16+ }
17+ };
18+}
19+
5pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
20pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
6 let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() {
21 let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() {
7 AppSettings::ColoredHelp
22 AppSettings::ColoredHelp
@@ -10,7 +25,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
10 };
25 };
11
26
12 let mut app = ClapApp::new(crate_name!())
27 let mut app = ClapApp::new(crate_name!())
13− .version(crate_version!())
28+ .version(VERSION.as_str())
14 .global_setting(clap_color_setting)
29 .global_setting(clap_color_setting)
15 .global_setting(AppSettings::DeriveDisplayOrder)
30 .global_setting(AppSettings::DeriveDisplayOrder)
16 .global_setting(AppSettings::UnifiedHelpMessage)
31 .global_setting(AppSettings::UnifiedHelpMessage)