How sleepymincy/mommy works
Project type and purpose
• This is a small Rust‐based CLI tool (“mommy”) whose sole purpose is to print randomized affirmations (or gentle chastisements) in your terminal after each command.
File structure
• Top level:
• Cargo.toml / Cargo.lock: Rust project manifest & dependencies.
• src/: main source code broken into modules:
– main.rs: entry point, orchestrates execution.
– config.rs: reading & parsing environment variables into app config.
– affirmations.rs: loading JSON, selecting messages.
– mommy.rs: core business logic (tie config + affirmations together).
– utils.rs: misc helpers.
• assets/affirmations.json: default affirmations data file.
• .github/workflows/rust.yml: CI build workflow.
• README.md: user & developer documentation.
Key components
a. CLI Interface (main.rs)
– Reads CLI args (exit code or command).
– Invokes the core logic.
b. Configuration Layer (config.rs)
– Reads environment variables (SHELL_MOMMYS_*).
– Builds a Config struct.
c. Asset Loader (affirmations.rs)
– If SHELL_MOMMYS_AFFIRMATIONS set, load JSON from path.
– Otherwise fall back to embedded JSON (assets/affirmations.json).
– Parses into Affirmation objects.
d. Core Logic (mommy.rs)
– Receives Config + Affirmations + exit code.
– Chooses positive or negative message based on exit code and flags.
– Wraps the chosen affirmation text.
f. Utilities (utils.rs)
– Helper functions (random selection, parsing RGB, splitting options).
g. Output (stdout)
– Terminal prints the styled affirmation.
Relationships and data flow
• main.rs → config.rs (load config)
• main.rs → affirmations.rs (load messages)
• main.rs → mommy.rs (pass config + data + exit code)
• mommy.rs → utils.rs (random pick, parsing)
• mommy.rs → stdout
Architectural patterns & principles
• Modular decomposition: each Rust module has a single responsibility.
• Dependency injection: main.rs injects env/config and data into core logic.
• Data flow is linear and functional—no global mutable state.
Technologies & frameworks
• Rust Cargo build system.
• serde_json for JSON parsing.
• rand crate (or std) for randomness.
• ANSI terminal styling.
Essential details to capture
• Explicit environment‐variable→Config mapping.
• Fallback logic: embedded JSON vs custom file.
• Conditional branching: positive vs negative response.
• ANSI styling pipeline after message selection.
• Integration points: user’s rc file hooking into prompt.