use const format for version string

This commit is contained in:
steven-omaha
2023-02-17 21:11:54 +01:00
parent 2768d41344
commit 4223eb19ed
3 changed files with 38 additions and 7 deletions
+2
View File
@@ -13,6 +13,7 @@ categories = ["command-line-utilities"]
alpm = "2.2"
anyhow = {workspace = true}
clap = "4.1"
const_format = { version = "0.2", default-features = false }
path-absolutize = "3.0"
regex = "1.7"
termios = "0.3"
@@ -23,3 +24,4 @@ serde_derive = "1.0"
serde = "1.0"
pacdef_macros = {path = "../pacdef_macros", version = "0.1"}
+9 -7
View File
@@ -5,6 +5,7 @@ use std::path::Path;
use anyhow::{anyhow, bail, ensure, Context, Result};
use clap::ArgMatches;
use const_format::formatcp;
use crate::action::*;
use crate::args;
@@ -338,11 +339,12 @@ fn show_error(error: &anyhow::Error, backend: &dyn Backend) {
}
pub const fn get_version_string() -> &'static str {
concat!(
"pacdef, version: ",
env!("CARGO_PKG_VERSION"),
" (",
env!("GIT_HASH"),
")",
)
const VERSION: &str = concat!("pacdef, version: ", env!("CARGO_PKG_VERSION"));
const HASH: &str = env!("GIT_HASH");
if HASH.is_empty() {
VERSION
} else {
formatcp!("{VERSION} ({HASH})")
}
}