1use std::path::PathBuf;
2use std::net::IpAddr;
3
4use easy_repl::{Repl, CommandStatus, command};
5use anyhow::{self, Context};
6
7fn main() -> anyhow::Result<()> {
8 let mut repl = Repl::builder()
9 .add("ls", command! {
10 "List files in a directory",
11 (dir: PathBuf) => |dir: PathBuf| {
12 for entry in dir.read_dir()? {
13 println!("{}", entry?.path().to_string_lossy());
14 }
15 Ok(CommandStatus::Done)
16 }
17 })
18 .add("ipaddr", command! {
19 "Just parse and print the given IP address",
20 (ip: IpAddr) => |ip: IpAddr| {
21 println!("{}", ip);
22 Ok(CommandStatus::Done)
23 }
24 })
25 .build().context("Failed to create repl")?;
26
27 repl.run().context("Critical REPL error")
28}
29