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

Conversation

Enselic
Copy link
Collaborator

@Enselic Enselic commented Oct 23, 2021

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

src/bin/bat/clap_app.rs Outdated Show resolved Hide resolved
I had to use a `lazy_static` due to that the clap API that only accepts a
reference to a version string. And, in our code, only a 'static reference to a
version string.

Code could probably be refactored to accept a "normal" reference, but that would
be a major undertaking.
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Enselic Enselic merged commit 4081ace into sharkdp:master Oct 24, 2021
@Enselic Enselic deleted the git-hash-in-version branch October 27, 2021 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants