sal/herodo/README.md
Mahmoud-Emad c94467c205 feat: Add herodo package to workspace
- Added the `herodo` package to the workspace.
- Updated the MONOREPO_CONVERSION_PLAN.md to reflect
  the completion of the herodo package conversion.
- Updated README.md and build_herodo.sh to reflect the
  new package structure.
- Created herodo/Cargo.toml, herodo/README.md,
  herodo/src/main.rs, herodo/src/lib.rs, and
  herodo/tests/integration_tests.rs and
  herodo/tests/unit_tests.rs.
2025-06-23 13:19:20 +03:00

143 lines
3.3 KiB
Markdown

# 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:
```bash
cd herodo
cargo build --release
```
The executable will be available at `target/release/herodo`.
## Usage
### Execute a Single Script
```bash
herodo path/to/script.rhai
```
### Execute All Scripts in a Directory
```bash
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
```rhai
// hello.rhai
println("Hello from Herodo!");
let result = 42 * 2;
println("Result: " + result);
```
### Using SAL Functions
```rhai
// 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
```rhai
// 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:
```bash
RUST_LOG=debug herodo script.rhai
```
## Testing
Run the test suite:
```bash
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