Include git hash in bat -V
and bat --version
output if present by Enselic · Pull Request #1921 · sharkdp/bat (original) (raw)
I had to use a lazy_static
due to the strange clap API that only accepts a reference to a version string. And, in our current code, only a 'static reference to a version string is accepted. Code could of course be refactored, but it would be way more messy.
I have several binaries of bat
lying around everywhere, and with this PR, I (and anyone else of course) can just do bat -V
to find out exactly what version of bat is at hand. Right now I have to do bat --diagnostics | head
, which is too unergonomic for my taste.
I could of course have a local script to avoid repetition, but who wants to local scripts for these kinds of things?
The output looks like this:
% cargo run -- -V
bat 0.18.3 (9291a79)
% cargo run -- --version
bat 0.18.3 (9291a79)
which is identical to the output format in --diagnostic
:
% cargo run -- --diagnostic | head -n 3
#### Software version
bat 0.18.3 (9291a79)
If no git repo is available at build time, the output is the same as before:
% touch src/bin/bat/main.rs # force rebuild
% GIT_DIR=/not-present cargo run -- -V
bat 0.18.3
% GIT_DIR=/not-present cargo run -- --version
bat 0.18.3