Allow abbreviating functions ending in _directory to _dir (#2235)

This commit is contained in:
Casey Rodarmor 2024-07-07 15:47:18 -07:00 committed by GitHub
parent 5e9f46e855
commit f1020b4e6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 1 deletions

View File

@ -1349,6 +1349,11 @@ Done!
`just` provides a few built-in functions that might be useful when writing
recipes.
All functions ending in `_directory` can be abbreviated to `_dir`. So
`home_directory()` can also be written as `home_dir()`. In addition,
`invocation_directory_native()` can be abbreviated to
`invocation_dir_native()`.
#### System Information
- `arch()` — Instruction set architecture. Possible values are: `"aarch64"`,

View File

@ -32,7 +32,15 @@ impl<'src: 'run, 'run> Context<'src, 'run> {
}
pub(crate) fn get(name: &str) -> Option<Function> {
let function = match name {
let name = if let Some(prefix) = name.strip_suffix("_dir") {
format!("{prefix}_directory")
} else if let Some(prefix) = name.strip_suffix("_dir_native") {
format!("{prefix}_directory_native")
} else {
name.into()
};
let function = match name.as_str() {
"absolute_path" => Unary(absolute_path),
"append" => Binary(append),
"arch" => Nullary(arch),

View File

@ -1068,3 +1068,33 @@ fn unary_argument_count_mismamatch_error_message() {
.status(EXIT_FAILURE)
.run();
}
#[test]
fn dir_abbreviations_are_accepted() {
Test::new()
.justfile(
"
abbreviated := justfile_dir()
unabbreviated := justfile_directory()
@foo:
# {{ assert(abbreviated == unabbreviated, 'fail') }}
",
)
.run();
}
#[test]
fn invocation_dir_native_abbreviation_is_accepted() {
Test::new()
.justfile(
"
abbreviated := invocation_directory_native()
unabbreviated := invocation_dir_native()
@foo:
# {{ assert(abbreviated == unabbreviated, 'fail') }}
",
)
.run();
}