From 7f4f4ba09e6907c446867d60db3ee08a873fdf7b Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Thu, 23 Feb 2023 21:30:19 +0100 Subject: [PATCH] add better version string --- crates/pacdef_core/src/core.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index d7e5844..8092ca2 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -147,7 +147,7 @@ impl Pacdef { #[allow(clippy::unused_self)] fn show_version(self) { - println!("{}", get_version_string()); + println!("{}", get_name_and_version()); } fn show_unmanaged_packages(mut self) -> Result<()> { @@ -348,8 +348,16 @@ fn show_error(error: &anyhow::Error, backend: &dyn Backend) { } } +/// If the crate was compiled from git, return `pacdef, ()`. +/// Otherwise return `pacdef, `. +const fn get_name_and_version() -> &'static str { + formatcp!("pacdef, version {}", get_version_string()) +} + +/// If the crate was compiled from git, return ` ()`. Otherwise +/// return ``. pub const fn get_version_string() -> &'static str { - const VERSION: &str = concat!("pacdef, version: ", env!("CARGO_PKG_VERSION")); + const VERSION: &str = env!("CARGO_PKG_VERSION"); const HASH: &str = env!("GIT_HASH"); if HASH.is_empty() {