good-morning 0.1.2

A welcome message generator.
Documentation

good-morning

A tiny Rust crate that generates welcome messages.

Install

Add this crate to your Cargo.toml:

[dependencies]
good-morning = "0.1"

Usage

Basic usage: create GoodMorning, load a template, provide arguments, and execute.

use good_morning::GoodMorning;
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
	let mut gm = GoodMorning::new();

	// Load a single template (supports variables)
	gm.load_template("Hello, {name}!")?;

	let args = HashMap::from([
		("name".to_string(), "World".to_string()),
	]);

	let msg = gm.execute(&args)?;
	println!("{}", msg); // Hello, World!

	Ok(())
}

Modifiers

Add a modifier after the variable name (e.g., uppercase / lowercase).

use good_morning::GoodMorning;
use std::collections::HashMap;

let mut gm = GoodMorning::new();
gm.load_template("Hello, {name:uppercase}!")?;

let args = HashMap::from([
	("name".to_string(), "alice".to_string()),
]);

let msg = gm.execute(&args)?;
assert_eq!(msg, "Hello, ALICE!");

Load templates from file

Load multiple templates at once (lines starting with # are comments).

use good_morning::GoodMorning;

let mut gm = GoodMorning::new();
gm.load_templates_from_file("assets/templates.txt")?;

Choose template by required flags

When multiple templates exist, use execute_with_required to require specific flags (flags are derived from variable names).

use good_morning::GoodMorning;
use std::collections::HashMap;

let mut gm = GoodMorning::new();
gm.load_template("Hello, {name}!")?;

let args = HashMap::from([
	("name".to_string(), "Bob".to_string()),
]);

let msg = gm.execute_with_required(&args, vec!["name".to_string()])?;

Documentation

Full API docs on docs.rs: https://docs.rs/good-morning

More examples in src and the API example in examples/api_server.

License

MIT