use std::{cell::RefCell};
use easy_repl::{Repl, CommandStatus, command};
use anyhow::{self, Context};
fn main() -> anyhow::Result<()> {
let counter = RefCell::new(0);
let ref1 = &counter;
let ref2 = &counter;
let mut repl = Repl::builder()
.add("inc", command! {
"Increment counter",
() => || {
*ref1.borrow_mut() += 1;
println!("counter = {}", ref1.borrow());
Ok(CommandStatus::Done)
},
})
.add("dec", command! {
"Decrement counter",
() => || {
*ref2.borrow_mut() -= 1;
println!("counter = {}", ref2.borrow());
Ok(CommandStatus::Done)
},
})
.build().context("Failed to create repl")?;
repl.run().context("Critical REPL error")?;
Ok(())
}