Skip to content

Commit

Permalink
feat: add version
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Dec 16, 2024
1 parent f3afc35 commit 98b3951
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn commit_hash() -> String {
let output = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
String::from_utf8(output.stdout).unwrap()
}

fn main() {
let hash = commit_hash();
println!("cargo:rerun-if-env-changed=COMMIT_HASH");
println!("cargo:rustc-env=COMMIT_HASH={}", hash);
}
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ fn main() -> Result<()> {
let start_time = Instant::now();
log::init_logger();

// Version
let args: Vec<String> = std::env::args().collect();
if args.contains(&"-v".to_string()) || args.contains(&"--version".to_string()) {
let commit_hash = env!("COMMIT_HASH");

println!(
"{} {}{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
if commit_hash.is_empty() {
"".to_string()
} else {
format!(" ({})", commit_hash).to_string()
}
);
return Ok(());
}

let args = Args::parse();

if !args.no_keep_awake {
Expand Down

0 comments on commit 98b3951

Please sign in to comment.