diff --git a/README.md b/README.md
index ee98348101..f98dabf9e3 100644
--- a/README.md
+++ b/README.md
@@ -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()`1.15.0 - Number of logical CPUs.
+- `num_cpus()`1.15.0 — 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()`master — The version of `just` being run, e.g. `"1.42.5"`.
For example:
diff --git a/examples/kitchen-sink.just b/examples/kitchen-sink.just
index 6e23fdfa07..28d6fe5f1c 100644
--- a/examples/kitchen-sink.just
+++ b/examples/kitchen-sink.just
@@ -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/"
diff --git a/src/function.rs b/src/function.rs
index 7cd078badf..2673e66034 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -73,6 +73,7 @@ pub(crate) fn get(name: &str) -> Option {
"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
diff --git a/tests/functions.rs b/tests/functions.rs
index bd2b109f79..d99ed23e39 100644
--- a/tests/functions.rs
+++ b/tests/functions.rs
@@ -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(),
)