diff --git a/crates/nu-cmd-lang/src/core_commands/version.rs b/crates/nu-cmd-lang/src/core_commands/version.rs index ae70ec0dd8..6af44035d5 100644 --- a/crates/nu-cmd-lang/src/core_commands/version.rs +++ b/crates/nu-cmd-lang/src/core_commands/version.rs @@ -1,3 +1,5 @@ +use std::sync::OnceLock; + use nu_engine::command_prelude::*; use nu_protocol::engine::StateWorkingSet; use shadow_rs::shadow; @@ -56,8 +58,12 @@ impl Command for Version { } pub fn version(engine_state: &EngineState, call: &Call) -> Result { - // Pre-allocate the arrays in the worst case (12 items): + // Pre-allocate the arrays in the worst case (17 items): // - version + // - major + // - minor + // - patch + // - pre // - branch // - commit_hash // - build_os @@ -66,15 +72,23 @@ pub fn version(engine_state: &EngineState, call: &Call) -> Result Result = OnceLock::new(); + + let &(major, minor, patch) = VERSION_NUMBERS.get_or_init(|| { + ( + build::PKG_VERSION_MAJOR.parse().expect("Always set"), + build::PKG_VERSION_MINOR.parse().expect("Always set"), + build::PKG_VERSION_PATCH.parse().expect("Always set"), + ) + }); + record.push("major", Value::int(major as _, head)); + record.push("minor", Value::int(minor as _, head)); + record.push("patch", Value::int(patch as _, head)); +} + fn global_allocator() -> &'static str { if cfg!(feature = "mimalloc") { "mimalloc"