Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include git hash in bat -V and bat --version output if present #1921

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

- Add PowerShell completion, see #1826 (@rashil2000)
- Minimum supported Rust version (MSRV) bumped to 1.46
- Include git hash in `bat -V` and `bat --version` output if present. See #1921 (@Enselic)

## Syntaxes

Expand Down
17 changes: 16 additions & 1 deletion src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup
use std::env;
use std::path::Path;

lazy_static::lazy_static! {
static ref VERSION: String = {
#[cfg(feature = "bugreport")]
let git_version = bugreport::git_version!(fallback = "");
#[cfg(not(feature = "bugreport"))]
let git_version = "";

if git_version.is_empty() {
crate_version!().to_string()
} else {
format!("{} ({})", crate_version!(), git_version)
}
};
}

pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() {
AppSettings::ColoredHelp
Expand All @@ -10,7 +25,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
};

let mut app = ClapApp::new(crate_name!())
.version(crate_version!())
.version(VERSION.as_str())
.global_setting(clap_color_setting)
.global_setting(AppSettings::DeriveDisplayOrder)
.global_setting(AppSettings::UnifiedHelpMessage)
Expand Down