feat: implement just_version() function

implement #2616
This commit is contained in:
Yuri Astrakhan 2025-09-26 00:34:55 -04:00
parent b7e7c46495
commit 21cde44358
4 changed files with 37 additions and 18 deletions

View file

@ -1628,12 +1628,13 @@ All functions ending in `_directory` can be abbreviated to `_dir`. So
`"arm"`, `"asmjs"`, `"hexagon"`, `"mips"`, `"msp430"`, `"powerpc"`,
`"powerpc64"`, `"s390x"`, `"sparc"`, `"wasm32"`, `"x86"`, `"x86_64"`, and
`"xcore"`.
- `num_cpus()`<sup>1.15.0</sup> - Number of logical CPUs.
- `num_cpus()`<sup>1.15.0</sup> Number of logical CPUs.
- `os()` — Operating system. Possible values are: `"android"`, `"bitrig"`,
`"dragonfly"`, `"emscripten"`, `"freebsd"`, `"haiku"`, `"ios"`, `"linux"`,
`"macos"`, `"netbsd"`, `"openbsd"`, `"solaris"`, and `"windows"`.
- `os_family()` — Operating system family; possible values are: `"unix"` and
`"windows"`.
- `just_version()`<sup>master</sup> — The version of `just` being run, e.g. `"1.42.5"`.
For example:

View file

@ -5,6 +5,12 @@ set positional-arguments
set dotenv-load
set export
_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
'yes'
} else {
error('just version 1.43.0 or greater is required, found ' + just_version())
}
alias s := serve
bt := '0'
@ -16,7 +22,7 @@ log := "warn"
export JUST_LOG := (log + "ing" + `grep loop /etc/networks | cut -f2`)
tmpdir := `mktemp`
version := "0.2.7"
version := just_version()
tardir := tmpdir / "awesomesauce-" + version
foo1 := / "tmp"
foo2_3 := "a/"

View file

@ -73,6 +73,7 @@ pub(crate) fn get(name: &str) -> Option<Function> {
"join" => BinaryPlus(join),
"just_executable" => Nullary(just_executable),
"just_pid" => Nullary(just_pid),
"just_version" => Nullary(just_version),
"justfile" => Nullary(justfile),
"justfile_directory" => Nullary(justfile_directory),
"kebabcase" => Unary(kebabcase),
@ -398,6 +399,10 @@ fn just_pid(_context: Context) -> FunctionResult {
Ok(std::process::id().to_string())
}
fn just_version(_context: Context) -> FunctionResult {
Ok(env!("CARGO_PKG_VERSION").to_string())
}
fn justfile(context: Context) -> FunctionResult {
context
.evaluator

View file

@ -6,26 +6,28 @@ fn test_os_arch_functions_in_interpolation() {
.justfile(
r"
foo:
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}}
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}} {{just_version()}}
",
)
.stdout(
format!(
"{} {} {} {}\n",
"{} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)
.stderr(
format!(
"echo {} {} {} {}\n",
"echo {} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)
@ -41,28 +43,31 @@ a := arch()
o := os()
f := os_family()
n := num_cpus()
v := just_version()
foo:
echo {{a}} {{o}} {{f}} {{n}}
echo {{a}} {{o}} {{f}} {{n}} {{v}}
",
)
.stdout(
format!(
"{} {} {} {}\n",
"{} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)
.stderr(
format!(
"echo {} {} {} {}\n",
"echo {} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)
@ -397,27 +402,29 @@ fn test_os_arch_functions_in_default() {
Test::new()
.justfile(
r"
foo a=arch() o=os() f=os_family() n=num_cpus():
echo {{a}} {{o}} {{f}} {{n}}
foo a=arch() o=os() f=os_family() n=num_cpus() v=just_version():
echo {{a}} {{o}} {{f}} {{n}} {{v}}
",
)
.stdout(
format!(
"{} {} {} {}\n",
"{} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)
.stderr(
format!(
"echo {} {} {} {}\n",
"echo {} {} {} {} {}\n",
target::arch(),
target::os(),
target::family(),
num_cpus::get()
num_cpus::get(),
env!("CARGO_PKG_VERSION"),
)
.as_str(),
)