Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add the `mycelium` package to the workspace members. - Add `sal-mycelium` dependency to `Cargo.toml`. - Update MONOREPO_CONVERSION_PLAN.md to reflect the addition and completion of the mycelium package.
200 lines
4.7 KiB
Rust
200 lines
4.7 KiB
Rust
//! Rhai scripting integration for the SAL library
|
|
//!
|
|
//! This module provides integration with the Rhai scripting language,
|
|
//! allowing SAL functions to be called from Rhai scripts.
|
|
|
|
mod buildah;
|
|
mod core;
|
|
pub mod error;
|
|
mod nerdctl;
|
|
mod os;
|
|
mod platform;
|
|
mod postgresclient;
|
|
mod process;
|
|
|
|
mod rfs;
|
|
mod screen;
|
|
mod text;
|
|
mod vault;
|
|
mod zinit;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
// Re-export common Rhai types for convenience
|
|
pub use rhai::{Array, Dynamic, Engine, EvalAltResult, Map};
|
|
|
|
// Re-export error module
|
|
pub use error::*;
|
|
|
|
// Re-export specific functions from modules to avoid name conflicts
|
|
pub use os::{
|
|
delete,
|
|
// Download functions
|
|
download,
|
|
download_install,
|
|
// File system functions
|
|
exist,
|
|
file_size,
|
|
find_dir,
|
|
find_dirs,
|
|
find_file,
|
|
find_files,
|
|
mkdir,
|
|
register_os_module,
|
|
rsync,
|
|
};
|
|
|
|
// Re-export Redis client module registration function
|
|
pub use sal_redisclient::rhai::register_redisclient_module;
|
|
|
|
// Re-export PostgreSQL client module registration function
|
|
pub use postgresclient::register_postgresclient_module;
|
|
|
|
pub use process::{
|
|
kill,
|
|
process_get,
|
|
process_list,
|
|
register_process_module,
|
|
// Run functions
|
|
// Process management functions
|
|
which,
|
|
};
|
|
|
|
// Re-export buildah functions
|
|
pub use buildah::bah_new;
|
|
pub use buildah::register_bah_module;
|
|
|
|
// Re-export nerdctl functions
|
|
pub use nerdctl::register_nerdctl_module;
|
|
pub use nerdctl::{
|
|
nerdctl_copy,
|
|
nerdctl_exec,
|
|
nerdctl_image_build,
|
|
nerdctl_image_commit,
|
|
nerdctl_image_pull,
|
|
nerdctl_image_push,
|
|
nerdctl_image_remove,
|
|
nerdctl_image_tag,
|
|
// Image functions
|
|
nerdctl_images,
|
|
nerdctl_list,
|
|
nerdctl_remove,
|
|
// Container functions
|
|
nerdctl_run,
|
|
nerdctl_run_with_name,
|
|
nerdctl_run_with_port,
|
|
nerdctl_stop,
|
|
};
|
|
|
|
// Re-export RFS module
|
|
pub use rfs::register as register_rfs_module;
|
|
|
|
// Re-export git module from sal-git package
|
|
pub use sal_git::rhai::register_git_module;
|
|
pub use sal_git::{GitRepo, GitTree};
|
|
|
|
// Re-export zinit module
|
|
pub use zinit::register_zinit_module;
|
|
|
|
// Re-export mycelium module
|
|
pub use sal_mycelium::rhai::register_mycelium_module;
|
|
|
|
// Re-export text module
|
|
pub use text::register_text_module;
|
|
// Re-export text functions directly from text module
|
|
pub use crate::text::{
|
|
// Dedent functions
|
|
dedent,
|
|
// Fix functions
|
|
name_fix,
|
|
path_fix,
|
|
prefix,
|
|
};
|
|
|
|
// Re-export TextReplacer functions
|
|
pub use text::*;
|
|
|
|
// Re-export crypto module
|
|
pub use vault::register_crypto_module;
|
|
|
|
// Rename copy functions to avoid conflicts
|
|
pub use os::copy as os_copy;
|
|
|
|
/// Register all SAL modules with the Rhai engine
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `engine` - The Rhai engine to register the modules with
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```ignore
|
|
/// use rhai::Engine;
|
|
/// use sal::rhai;
|
|
///
|
|
/// let mut engine = Engine::new();
|
|
/// rhai::register(&mut engine);
|
|
///
|
|
/// // Now you can use SAL functions in Rhai scripts
|
|
/// // You can evaluate Rhai scripts with SAL functions
|
|
/// let result = engine.eval::<i64>("exist('some_file.txt')").unwrap();
|
|
/// ```
|
|
pub fn register(engine: &mut Engine) -> Result<(), Box<rhai::EvalAltResult>> {
|
|
// Register Core module functions
|
|
core::register_core_module(engine)?;
|
|
|
|
// Register OS module functions
|
|
os::register_os_module(engine)?;
|
|
|
|
// Register Process module functions
|
|
process::register_process_module(engine)?;
|
|
|
|
// Register Buildah module functions
|
|
buildah::register_bah_module(engine)?;
|
|
|
|
// Register Nerdctl module functions
|
|
nerdctl::register_nerdctl_module(engine)?;
|
|
|
|
// Register Git module functions
|
|
sal_git::rhai::register_git_module(engine)?;
|
|
|
|
// Register Zinit module functions
|
|
zinit::register_zinit_module(engine)?;
|
|
|
|
// Register Mycelium module functions
|
|
sal_mycelium::rhai::register_mycelium_module(engine)?;
|
|
|
|
// Register Text module functions
|
|
text::register_text_module(engine)?;
|
|
|
|
// Register RFS module functions
|
|
rfs::register(engine)?;
|
|
|
|
// Register Crypto module functions
|
|
vault::register_crypto_module(engine)?;
|
|
|
|
// Register Redis client module functions
|
|
sal_redisclient::rhai::register_redisclient_module(engine)?;
|
|
|
|
// Register PostgreSQL client module functions
|
|
postgresclient::register_postgresclient_module(engine)?;
|
|
|
|
// Register Platform module functions
|
|
platform::register(engine);
|
|
|
|
// Register Screen module functions
|
|
screen::register(engine);
|
|
|
|
// Register utility functions
|
|
engine.register_fn("is_def_fn", |_name: &str| -> bool {
|
|
// This is a utility function to check if a function is defined in the engine
|
|
// For testing purposes, we'll just return true
|
|
true
|
|
});
|
|
|
|
// Future modules can be registered here
|
|
|
|
Ok(())
|
|
}
|