Make path_exists() relative to current directory (#1122)
This commit is contained in:
parent
88922b8974
commit
3118ce7211
@ -154,7 +154,7 @@ fn just_executable(_context: &FunctionContext) -> Result<String, String> {
|
|||||||
exe_path.to_str().map(str::to_owned).ok_or_else(|| {
|
exe_path.to_str().map(str::to_owned).ok_or_else(|| {
|
||||||
format!(
|
format!(
|
||||||
"Executable path is not valid unicode: {}",
|
"Executable path is not valid unicode: {}",
|
||||||
exe_path.to_string_lossy()
|
exe_path.display()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ fn justfile(context: &FunctionContext) -> Result<String, String> {
|
|||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
format!(
|
format!(
|
||||||
"Justfile path is not valid unicode: {}",
|
"Justfile path is not valid unicode: {}",
|
||||||
context.search.justfile.to_string_lossy()
|
context.search.justfile.display()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ fn justfile_directory(context: &FunctionContext) -> Result<String, String> {
|
|||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
format!(
|
format!(
|
||||||
"Justfile directory is not valid unicode: {}",
|
"Justfile directory is not valid unicode: {}",
|
||||||
justfile_directory.to_string_lossy()
|
justfile_directory.display()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -211,8 +211,15 @@ fn parent_directory(_context: &FunctionContext, path: &str) -> Result<String, St
|
|||||||
.ok_or_else(|| format!("Could not extract parent directory from `{}`", path))
|
.ok_or_else(|| format!("Could not extract parent directory from `{}`", path))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_exists(_context: &FunctionContext, path: &str) -> Result<String, String> {
|
fn path_exists(context: &FunctionContext, path: &str) -> Result<String, String> {
|
||||||
Ok(Utf8Path::new(path).exists().to_string())
|
Ok(
|
||||||
|
context
|
||||||
|
.search
|
||||||
|
.working_directory
|
||||||
|
.join(path)
|
||||||
|
.exists()
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quote(_context: &FunctionContext, s: &str) -> Result<String, String> {
|
fn quote(_context: &FunctionContext, s: &str) -> Result<String, String> {
|
||||||
|
@ -403,3 +403,18 @@ fn test_path_exists_filepath_doesnt_exist() {
|
|||||||
.stdout("false")
|
.stdout("false")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn path_exists_subdir() {
|
||||||
|
Test::new()
|
||||||
|
.tree(tree! {
|
||||||
|
foo: "",
|
||||||
|
bar: {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.justfile("x := path_exists('foo')")
|
||||||
|
.current_dir("bar")
|
||||||
|
.args(&["--evaluate", "x"])
|
||||||
|
.stdout("true")
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user