This commit is contained in:
2025-04-05 07:23:07 +02:00
parent 6de7bf9b56
commit 6d4c1742e7
14 changed files with 533 additions and 455 deletions

View File

@@ -35,6 +35,10 @@ pub fn register_os_module(engine: &mut Engine) -> Result<(), Box<EvalAltResult>>
engine.register_fn("file_write", file_write);
engine.register_fn("file_write_append", file_write_append);
// Register command check functions
engine.register_fn("which", which);
engine.register_fn("cmd_ensure_exists", cmd_ensure_exists);
// Register download functions
engine.register_fn("download", download);
engine.register_fn("download_install", download_install);
@@ -176,4 +180,19 @@ pub fn download(url: &str, dest: &str, min_size_kb: i64) -> Result<String, Box<E
/// Download a file and install it if it's a supported package format.
pub fn download_install(url: &str, min_size_kb: i64) -> Result<String, Box<EvalAltResult>> {
os::download_install(url, min_size_kb).to_rhai_error()
}
/// Wrapper for os::which
///
/// Check if a command exists in the system PATH.
pub fn which(command: &str) -> String {
os::which(command)
}
/// Wrapper for os::cmd_ensure_exists
///
/// Ensure that one or more commands exist in the system PATH.
/// If any command doesn't exist, an error is thrown.
pub fn cmd_ensure_exists(commands: &str) -> Result<String, Box<EvalAltResult>> {
os::cmd_ensure_exists(commands).to_rhai_error()
}