sal/herodo/README.md
Mahmoud-Emad e01b83f12a
Some checks are pending
Test Publishing Setup / Test Publishing Setup (pull_request) Waiting to run
feat: Add CI/CD workflows for testing and publishing SAL crates
- Add a workflow for testing the publishing setup
- Add a workflow for publishing SAL crates to crates.io
- Improve crate metadata and version management
- Add optional dependencies for modularity
- Improve documentation for publishing and usage
2025-07-01 08:34:20 +03:00

3.8 KiB

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 and Install

git clone https://github.com/PlanetFirst/sal.git
cd sal
./build_herodo.sh

This script will:

  • Build herodo in debug mode
  • Install it to ~/hero/bin/herodo (non-root) or /usr/local/bin/herodo (root)
  • Make it available in your PATH

Note: If using the non-root installation, make sure ~/hero/bin is in your PATH:

export PATH="$HOME/hero/bin:$PATH"

Install from crates.io (Coming Soon)

# This will be available once herodo is published to crates.io
cargo install herodo

Note: herodo is not yet published to crates.io due to publishing rate limits. It will be available soon.

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