start core info module; move version to info
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
ee864bcd9e
commit
d7d874f88d
3 changed files with 13 additions and 8 deletions
4
src/core/info/mod.rs
Normal file
4
src/core/info/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//! Information about the project. This module contains version, build, system,
|
||||
//! etc information which can be queried by admins or used by developers.
|
||||
|
||||
pub mod version;
|
38
src/core/info/version.rs
Normal file
38
src/core/info/version.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
//! one true function for returning the conduwuit version with the necessary
|
||||
//! CONDUWUIT_VERSION_EXTRA env variables used if specified
|
||||
//!
|
||||
//! Set the environment variable `CONDUWUIT_VERSION_EXTRA` to any UTF-8 string
|
||||
//! to include it in parenthesis after the SemVer version. A common value are
|
||||
//! git commit hashes.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static BRANDING: &str = "Conduwuit";
|
||||
static SEMANTIC: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static VERSION: OnceLock<String> = OnceLock::new();
|
||||
static USER_AGENT: OnceLock<String> = OnceLock::new();
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn name() -> &'static str { BRANDING }
|
||||
|
||||
#[inline]
|
||||
pub fn version() -> &'static str { VERSION.get_or_init(init_version) }
|
||||
|
||||
#[inline]
|
||||
pub fn user_agent() -> &'static str { USER_AGENT.get_or_init(init_user_agent) }
|
||||
|
||||
fn init_user_agent() -> String { format!("{}/{}", name(), version()) }
|
||||
|
||||
fn init_version() -> String {
|
||||
option_env!("CONDUWUIT_VERSION_EXTRA")
|
||||
.or(option_env!("CONDUIT_VERSION_EXTRA"))
|
||||
.map_or(SEMANTIC.to_owned(), |extra| {
|
||||
if extra.is_empty() {
|
||||
SEMANTIC.to_owned()
|
||||
} else {
|
||||
format!("{SEMANTIC} ({extra})")
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue