Skip to main content

minimal/
minimal.rs

1use easy_repl::{Repl, CommandStatus, command};
2use anyhow::{self, Context};
3
4fn main() -> anyhow::Result<()> {
5    let mut repl = Repl::builder()
6        .add("hello", command! {
7            "Say hello",
8            (name: String) => |name| {
9                println!("Hello {}!", name);
10                Ok(CommandStatus::Done)
11            }
12        })
13        .add("add", command! {
14            "Add X to Y",
15            (X:i32, Y:i32) => |x, y| {
16                println!("{} + {} = {}", x, y, x + y);
17                Ok(CommandStatus::Done)
18            }
19        })
20        .build().context("Failed to create repl")?;
21
22    repl.run().context("Critical REPL error")?;
23
24    Ok(())
25}
26