sal/herodo
Mahmoud-Emad e125bb6511
Some checks failed
Rhai Tests / Run Rhai Tests (push) Has been cancelled
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled
feat: Migrate SAL to Cargo workspace
- Migrate individual modules to independent crates
- Refactor dependencies for improved modularity
- Update build system and testing infrastructure
- Update documentation to reflect new structure
2025-06-24 12:39:18 +03:00
..
src feat: Migrate SAL to Cargo workspace 2025-06-24 12:39:18 +03:00
tests feat: Migrate SAL to Cargo workspace 2025-06-24 12:39:18 +03:00
Cargo.toml feat: Migrate SAL to Cargo workspace 2025-06-24 12:39:18 +03:00
README.md feat: Add herodo package to workspace 2025-06-23 13:19:20 +03:00

Herodo - Rhai Script Executor for SAL

Version: 0.1.0

Herodo is a command-line utility that executes Rhai scripts with full access to the SAL (System Abstraction Layer) library. It provides a powerful scripting environment for automation and system management tasks.

Features

  • Single Script Execution: Execute individual .rhai script files
  • Directory Execution: Execute all .rhai scripts in a directory (recursively)
  • Sorted Execution: Scripts are executed in alphabetical order for predictable behavior
  • SAL Integration: Full access to all SAL modules and functions
  • Error Handling: Clear error messages and proper exit codes
  • Logging Support: Built-in logging with env_logger

Installation

Build the herodo binary:

cd herodo
cargo build --release

The executable will be available at target/release/herodo.

Usage

Execute a Single Script

herodo path/to/script.rhai

Execute All Scripts in a Directory

herodo path/to/scripts/

When given a directory, herodo will:

  1. Recursively find all .rhai files
  2. Sort them alphabetically
  3. Execute them in order
  4. Stop on the first error

Example Scripts

Basic Script

// hello.rhai
println("Hello from Herodo!");
let result = 42 * 2;
println("Result: " + result);

Using SAL Functions

// system_info.rhai
println("=== System Information ===");

// Check if a file exists
let config_exists = exist("/etc/hosts");
println("Config file exists: " + config_exists);

// Download a file
download("https://example.com/data.txt", "/tmp/data.txt");
println("File downloaded successfully");

// Execute a system command
let output = run("ls -la /tmp");
println("Directory listing:");
println(output.stdout);

Redis Operations

// redis_example.rhai
println("=== Redis Operations ===");

// Set a value
redis_set("app_status", "running");
println("Status set in Redis");

// Get the value
let status = redis_get("app_status");
println("Current status: " + status);

Available SAL Functions

Herodo provides access to all SAL modules through Rhai:

  • File System: exist(), mkdir(), delete(), file_size()
  • Downloads: download(), download_install()
  • Process Management: run(), kill(), process_list()
  • Redis: redis_set(), redis_get(), redis_del()
  • PostgreSQL: Database operations and management
  • Network: HTTP requests, SSH operations, TCP connectivity
  • Virtualization: Container operations with Buildah and Nerdctl
  • Text Processing: String manipulation and template rendering
  • And many more...

Error Handling

Herodo provides clear error messages and appropriate exit codes:

  • Exit Code 0: All scripts executed successfully
  • Exit Code 1: Error occurred (file not found, script error, etc.)

Logging

Enable detailed logging by setting the RUST_LOG environment variable:

RUST_LOG=debug herodo script.rhai

Testing

Run the test suite:

cd herodo
cargo test

The test suite includes:

  • Unit tests for core functionality
  • Integration tests with real script execution
  • Error handling scenarios
  • SAL module integration tests

Dependencies

  • rhai: Embedded scripting language
  • env_logger: Logging implementation
  • sal: System Abstraction Layer library

License

Apache-2.0