herolib-do 0.3.2

Interactive Rhai shell aggregating herolib packages
Documentation
# 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

```bash
git clone ???
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:
```bash
export PATH="$HOME/hero/bin:$PATH"
```

### Install from crates.io (Coming Soon)

```bash
# 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

```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