opt zgs version (#211)

This commit is contained in:
Bo QIU 2024-09-24 16:42:38 +08:00 committed by GitHub
parent 9cde84ae15
commit 84c415e959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 22 deletions

View File

@ -7,41 +7,42 @@ use target_info::Target;
/// ///
/// ## Example /// ## Example
/// ///
/// `Lighthouse/v1.5.1-67da032+` /// `v0.5.2` or `v0.5.2-1-67da032+`
pub const VERSION: &str = git_version!( pub const VERSION: &str = git_version!(
args = [ args = [
"--always", "--always",
"--dirty=+", "--dirty=+",
"--abbrev=7", "--abbrev=7",
// NOTE: using --match instead of --exclude for compatibility with old Git // NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol" // "--match=thiswillnevermatchlol"
"--tags",
], ],
prefix = "zgs/v0.0.1-", // prefix = "zgs/v0.0.1-",
fallback = "unknown" fallback = "unknown"
); );
/// Returns `VERSION`, but with platform information appended to the end. /// Returns `VERSION`, but with `zgs` prefix and platform information appended to the end.
/// ///
/// ## Example /// ## Example
/// ///
/// `zgs/v0.0.1-67da032+/x86_64-linux` /// `zgs/v0.5.2/x86_64-linux`
pub fn version_with_platform() -> String { pub fn version_with_platform() -> String {
format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) format!("zgs/{}/{}-{}", VERSION, Target::arch(), Target::os())
} }
#[cfg(test)] // #[cfg(test)]
mod test { // mod test {
use super::*; // use super::*;
use regex::Regex; // use regex::Regex;
#[test] // #[test]
fn version_formatting() { // fn version_formatting() {
let re = // let re =
Regex::new(r"^zgs/v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9])?-[[:xdigit:]]{7}\+?$").unwrap(); // Regex::new(r"^v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9])?-[[:xdigit:]]{7}\+?$").unwrap();
assert!( // assert!(
re.is_match(VERSION), // re.is_match(VERSION),
"version doesn't match regex: {}", // "version doesn't match regex: {}",
VERSION // VERSION
); // );
} // }
} // }

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = { version = "1.0.58", features = ["backtrace"] } anyhow = { version = "1.0.58", features = ["backtrace"] }
clap = { version = "4.5.17", features = ["cargo"] } clap = { version = "4.5.17", features = ["cargo", "string"] }
ctrlc = "3.2.2" ctrlc = "3.2.2"
error-chain = "0.12.4" error-chain = "0.12.4"
ethereum-types = "0.14" ethereum-types = "0.14"

View File

@ -10,4 +10,5 @@ pub fn cli_app() -> Command {
) )
.arg(arg!(--"db-max-num-chunks" [NUM] "Sets the max number of chunks to store in db (Default: None)")) .arg(arg!(--"db-max-num-chunks" [NUM] "Sets the max number of chunks to store in db (Default: None)"))
.allow_external_subcommands(true) .allow_external_subcommands(true)
.version(zgs_version::VERSION)
} }