Allow abbreviating functions ending in _directory
to _dir
(#2235)
This commit is contained in:
parent
5e9f46e855
commit
f1020b4e6a
@ -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"`,
|
||||
|
@ -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),
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user