# OS Module Examples

This directory contains examples demonstrating the OS module functionality.

## Examples

- `01_filesystem.rhai` - File system operations
- `02_platform.rhai` - Platform detection and checks
- `03_commands.rhai` - Command operations (which, cmd_ensure_exists)
- `04_download.rhai` - Download operations
- `05_package.rhai` - Package management

## Available Functions

### File System Operations
- `exist(path)` - Check if a file or directory exists
- `ensure(path)` - Ensure a path exists (throws error if not)
- `ensure_dir(path)` - Ensure a directory exists
- `ensure_file(path)` - Ensure a file exists
- `mkdir(path)` - Create a directory (and parents)
- `delete(path)` - Delete a file or directory
- `copy(src, dest)` - Copy a file or directory
- `copy_bin(src)` - Copy binary to system bin directory
- `mv(src, dest)` - Move a file or directory
- `file_read(path)` - Read file contents
- `file_write(path, content)` - Write to a file
- `file_write_append(path, content)` - Append to a file
- `file_size(path)` - Get file size in bytes
- `compare(path, expected)` - Compare file content with expected string
- `find_file(dir, pattern)` - Find a file by pattern
- `find_files(dir, pattern)` - Find multiple files
- `find_dir(dir, pattern)` - Find a directory by pattern
- `find_dirs(dir, pattern)` - Find multiple directories
- `chdir(path)` - Change current directory
- `rsync(src, dest)` - Sync directories
- `chmod_exec(path)` - Make a file executable

### Download Operations
- `download(url, dest_dir, min_size_kb)` - Download to directory
- `download_file(url, dest_file, min_size_kb)` - Download to specific file
- `download_install(url, min_size_kb)` - Download and install package

### Command Operations
- `which(cmd)` - Find command in PATH (returns path or empty string)
- `cmd_ensure_exists(cmds)` - Ensure commands exist (comma-separated)

### Package Management
- `package_platform()` - Get current platform (MacOS/Ubuntu/Unknown)
- `package_set_debug(bool)` - Enable/disable debug output
- `package_is_installed(pkg)` - Check if package is installed
- `package_search(query)` - Search for packages
- `package_list()` - List installed packages
- `package_update()` - Update package lists
- `package_upgrade()` - Upgrade all packages
- `package_install(pkg)` - Install a package
- `package_remove(pkg)` - Remove a package

### Platform Detection
- `platform_is_osx()` - Check if running on macOS
- `platform_is_linux()` - Check if running on Linux
- `platform_is_arm()` - Check if running on ARM
- `platform_is_x86()` - Check if running on x86
- `platform_check_linux_x86()` - Assert running on Linux x86
- `platform_check_macos_arm()` - Assert running on macOS ARM

## Running Examples

```bash
cd packages/os
herodo rhaiexamples/os/01_filesystem.rhai
herodo rhaiexamples/os/02_platform.rhai
herodo rhaiexamples/os/03_commands.rhai
herodo rhaiexamples/os/04_download.rhai
herodo rhaiexamples/os/05_package.rhai
```
