Skip to content

Commit

Permalink
Add support for querying the program version
Browse files Browse the repository at this point in the history
A user may be interested in understanding what version of the program is
running. With this change we enable clap's version printing feature to
emit program version and git SHA-1/tag, if present. We use the grev
crate for retrieving git version information.
  • Loading branch information
d-e-s-o committed Jul 16, 2024
1 parent 811075f commit da1e4bc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
Unreleased
----------
- Added support for `--version`/`-V` option to print program version
- Bumped `zbus` dependency to `4.0`


Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -34,9 +34,13 @@ codegen-units = 1
incremental = false
panic = "abort"

[build-dependencies]
anyhow = { version = "1.0.71", default-features = false, features = ["std"] }
grev = { version = "0.1.3", default-features = false }

[dependencies]
anyhow = { version = "1.0.71", default-features = false, features = ["std"] }
clap = {version = "4.1.4", features = ["derive"]}
clap = { version = "4.1.4", features = ["derive"] }
tokio = { version = "1.34", default-features = false, features = ["macros", "rt", "time"] }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "chrono", "env-filter", "fmt"] }
Expand Down
21 changes: 21 additions & 0 deletions build.rs
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Daniel Mueller (deso@posteo.net)
// SPDX-License-Identifier: GPL-3.0-or-later

use anyhow::Result;

use grev::git_revision_auto;


fn main() -> Result<()> {
let dir = env!("CARGO_MANIFEST_DIR");
if let Some(git_rev) = git_revision_auto(dir)? {
println!(
"cargo:rustc-env=VERSION={} ({})",
env!("CARGO_PKG_VERSION"),
git_rev
);
} else {
println!("cargo:rustc-env=VERSION={}", env!("CARGO_PKG_VERSION"));
}
Ok(())
}
1 change: 1 addition & 0 deletions src/main.rs
Expand Up @@ -87,6 +87,7 @@ fn parse_duration(s: &str) -> Result<Duration> {
/// A program/daemon sending notifications when the user should take a
/// break from staring at the screen.
#[derive(Debug, Parser)]
#[clap(version = env!("VERSION"))]
pub struct Args {
/// The duration that, if the user has been "goggling" for this long,
/// we post a notification.
Expand Down

0 comments on commit da1e4bc

Please sign in to comment.