herolib-core 0.1.0

Core utilities including text processing, networking, and HeroScript configuration language
Documentation

herolib-core

Core utilities for the SAL (System Abstraction Library) including text processing, networking, and the HeroScript configuration language.

Installation

cargo add herolib-core

Or add to your Cargo.toml:

[dependencies]
herolib-core = "0.1"

See https://crates.io/crates/herolib-core

Modules

heroscript

A defensive configuration and scripting language designed for safe, predictable system orchestration.

  • Parse and execute HeroScript configuration files
  • Type-safe parameter handling
  • Wildcard action filtering
  • Struct serialization with derive macros (ToHeroScript, FromHeroScript)
  • Source tracking and write-back support
  • Include system for modular scripts
use herolib_core::heroscript::{PlayBook, PlayBookNewArgs, FindArgs};

let script = "!!server.define name:web1 host:localhost port:8080";
let playbook = PlayBook::new(PlayBookNewArgs {
    text: script.to_string(),
    ..Default::default()
})?;

let action = playbook.get("server.define")?;
let name = action.params.get("name")?;
let port = action.params.get_u16("port")?;

text

Text processing and manipulation utilities.

  • dedent / prefix - Text indentation handling
  • name_fix / path_fix - String sanitization for filenames
  • TextReplacer - Regex and literal text replacement with chaining
  • TemplateBuilder - Tera-based template rendering
use herolib_core::text::{dedent, name_fix, TextReplacer};

let clean = dedent("    indented\n    text");
let safe = name_fix("Hello World!.txt");  // "hello_world_.txt"

let replacer = TextReplacer::builder()
    .pattern(r"\d+")
    .replacement("NUM")
    .regex(true)
    .build()?;
let result = replacer.replace("42 items");

net

Network connectivity utilities.

  • TCP port checking
  • HTTP endpoint validation
  • SSH connectivity testing
use herolib_core::net;

let is_up = net::tcp_check("localhost", 8080);

Features

Feature Description
default Base functionality
git Enable git operations in HeroScript include processing

Enable features in Cargo.toml:

[dependencies]
herolib-core = { version = "0.1", features = ["git"] }

Rhai Integration

All modules are available in Rhai scripts when using the herosal runtime.

// HeroScript
let pb = playbook_from_text("!!server.define name:web1 port:8080");
let server = pb.get("server.define");
print(server.get("name"));

// Text
let safe = name_fix("My File.txt");
let clean = dedent("    indented text");

// Replacer
let replacer = text_replacer_new()
    .pattern("old")
    .replacement("new")
    .build();
let result = replacer.replace("old text");

Related Packages

Package Description
herosal-system OS, filesystem, download, package management
herosal-clients Redis, PostgreSQL, MQTT, Mycelium clients
herosal-toschema HeroScript derive macros

License

See repository for license information.