Skip to content

Commit 21cde44

Browse files
committed
feat: implement just_version() function
implement #2616
1 parent b7e7c46 commit 21cde44

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,12 +1628,13 @@ All functions ending in `_directory` can be abbreviated to `_dir`. So
16281628
`"arm"`, `"asmjs"`, `"hexagon"`, `"mips"`, `"msp430"`, `"powerpc"`,
16291629
`"powerpc64"`, `"s390x"`, `"sparc"`, `"wasm32"`, `"x86"`, `"x86_64"`, and
16301630
`"xcore"`.
1631-
- `num_cpus()`<sup>1.15.0</sup> - Number of logical CPUs.
1631+
- `num_cpus()`<sup>1.15.0</sup> Number of logical CPUs.
16321632
- `os()` — Operating system. Possible values are: `"android"`, `"bitrig"`,
16331633
`"dragonfly"`, `"emscripten"`, `"freebsd"`, `"haiku"`, `"ios"`, `"linux"`,
16341634
`"macos"`, `"netbsd"`, `"openbsd"`, `"solaris"`, and `"windows"`.
16351635
- `os_family()` — Operating system family; possible values are: `"unix"` and
16361636
`"windows"`.
1637+
- `just_version()`<sup>master</sup> — The version of `just` being run, e.g. `"1.42.5"`.
16371638

16381639
For example:
16391640

examples/kitchen-sink.just

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ set positional-arguments
55
set dotenv-load
66
set export
77

8+
_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
9+
'yes'
10+
} else {
11+
error('just version 1.43.0 or greater is required, found ' + just_version())
12+
}
13+
814
alias s := serve
915

1016
bt := '0'
@@ -16,7 +22,7 @@ log := "warn"
1622
export JUST_LOG := (log + "ing" + `grep loop /etc/networks | cut -f2`)
1723

1824
tmpdir := `mktemp`
19-
version := "0.2.7"
25+
version := just_version()
2026
tardir := tmpdir / "awesomesauce-" + version
2127
foo1 := / "tmp"
2228
foo2_3 := "a/"

src/function.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub(crate) fn get(name: &str) -> Option<Function> {
7373
"join" => BinaryPlus(join),
7474
"just_executable" => Nullary(just_executable),
7575
"just_pid" => Nullary(just_pid),
76+
"just_version" => Nullary(just_version),
7677
"justfile" => Nullary(justfile),
7778
"justfile_directory" => Nullary(justfile_directory),
7879
"kebabcase" => Unary(kebabcase),
@@ -398,6 +399,10 @@ fn just_pid(_context: Context) -> FunctionResult {
398399
Ok(std::process::id().to_string())
399400
}
400401

402+
fn just_version(_context: Context) -> FunctionResult {
403+
Ok(env!("CARGO_PKG_VERSION").to_string())
404+
}
405+
401406
fn justfile(context: Context) -> FunctionResult {
402407
context
403408
.evaluator

tests/functions.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ fn test_os_arch_functions_in_interpolation() {
66
.justfile(
77
r"
88
foo:
9-
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}}
9+
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}} {{just_version()}}
1010
",
1111
)
1212
.stdout(
1313
format!(
14-
"{} {} {} {}\n",
14+
"{} {} {} {} {}\n",
1515
target::arch(),
1616
target::os(),
1717
target::family(),
18-
num_cpus::get()
18+
num_cpus::get(),
19+
env!("CARGO_PKG_VERSION"),
1920
)
2021
.as_str(),
2122
)
2223
.stderr(
2324
format!(
24-
"echo {} {} {} {}\n",
25+
"echo {} {} {} {} {}\n",
2526
target::arch(),
2627
target::os(),
2728
target::family(),
28-
num_cpus::get()
29+
num_cpus::get(),
30+
env!("CARGO_PKG_VERSION"),
2931
)
3032
.as_str(),
3133
)
@@ -41,28 +43,31 @@ a := arch()
4143
o := os()
4244
f := os_family()
4345
n := num_cpus()
46+
v := just_version()
4447
4548
foo:
46-
echo {{a}} {{o}} {{f}} {{n}}
49+
echo {{a}} {{o}} {{f}} {{n}} {{v}}
4750
",
4851
)
4952
.stdout(
5053
format!(
51-
"{} {} {} {}\n",
54+
"{} {} {} {} {}\n",
5255
target::arch(),
5356
target::os(),
5457
target::family(),
55-
num_cpus::get()
58+
num_cpus::get(),
59+
env!("CARGO_PKG_VERSION"),
5660
)
5761
.as_str(),
5862
)
5963
.stderr(
6064
format!(
61-
"echo {} {} {} {}\n",
65+
"echo {} {} {} {} {}\n",
6266
target::arch(),
6367
target::os(),
6468
target::family(),
65-
num_cpus::get()
69+
num_cpus::get(),
70+
env!("CARGO_PKG_VERSION"),
6671
)
6772
.as_str(),
6873
)
@@ -397,27 +402,29 @@ fn test_os_arch_functions_in_default() {
397402
Test::new()
398403
.justfile(
399404
r"
400-
foo a=arch() o=os() f=os_family() n=num_cpus():
401-
echo {{a}} {{o}} {{f}} {{n}}
405+
foo a=arch() o=os() f=os_family() n=num_cpus() v=just_version():
406+
echo {{a}} {{o}} {{f}} {{n}} {{v}}
402407
",
403408
)
404409
.stdout(
405410
format!(
406-
"{} {} {} {}\n",
411+
"{} {} {} {} {}\n",
407412
target::arch(),
408413
target::os(),
409414
target::family(),
410-
num_cpus::get()
415+
num_cpus::get(),
416+
env!("CARGO_PKG_VERSION"),
411417
)
412418
.as_str(),
413419
)
414420
.stderr(
415421
format!(
416-
"echo {} {} {} {}\n",
422+
"echo {} {} {} {} {}\n",
417423
target::arch(),
418424
target::os(),
419425
target::family(),
420-
num_cpus::get()
426+
num_cpus::get(),
427+
env!("CARGO_PKG_VERSION"),
421428
)
422429
.as_str(),
423430
)

0 commit comments

Comments
 (0)