add proper version string

This commit is contained in:
Dr. Matthias Ratajczak
2023-01-30 16:55:45 +01:00
parent b3d5aa0fce
commit b49e470b1d
5 changed files with 25 additions and 4 deletions
Generated
+1 -1
View File
@@ -182,7 +182,7 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "pacdef"
version = "0.1.0"
version = "1.0.0-alpha1"
dependencies = [
"alpm",
"anyhow",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "pacdef"
version = "0.1.0"
version = "1.0.0-alpha1"
edition = "2021"
[dependencies]
+10
View File
@@ -0,0 +1,10 @@
use std::process::Command;
fn main() {
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
+2 -1
View File
@@ -4,11 +4,12 @@ use clap::{Arg, ArgMatches, Command};
use path_absolutize::Absolutize;
use crate::action::*;
use crate::core::get_version_string;
fn get_arg_parser() -> Command {
Command::new("pacdef")
.about("declarative package manager for Arch Linux")
.version("1.0.0-alpha")
.version(get_version_string())
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(Command::new(CLEAN).about("remove unmanaged packages"))
+11 -1
View File
@@ -136,7 +136,7 @@ impl Pacdef {
}
fn show_version(self) {
println!("pacdef, version: {}", env!("CARGO_PKG_VERSION"));
println!("{}", get_version_string());
}
fn show_unmanaged_packages(mut self) {
@@ -289,3 +289,13 @@ fn show_error(error: anyhow::Error, backend: Box<dyn Backend>) {
None => println!("WARNING: skipping backend '{section}': {error}"),
}
}
pub(crate) const fn get_version_string() -> &'static str {
concat!(
"pacdef, version: ",
env!("CARGO_PKG_VERSION"),
" (",
env!("GIT_HASH"),
")",
)
}