emu/reedline-repl-rs/examples/hello_world.rs

24 lines
695 B
Rust
Raw Normal View History

2022-10-09 12:14:49 -05:00
//! Minimal example
use reedline_repl_rs::clap::{Arg, ArgMatches, Command};
use reedline_repl_rs::{Repl, Result};
/// Write "Hello" with given name
fn hello<T>(args: ArgMatches, _context: &mut T) -> Result<Option<String>> {
Ok(Some(format!("Hello, {}", args.value_of("who").unwrap())))
}
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.with_banner("Welcome to MyApp")
.with_command(
Command::new("hello")
.arg(Arg::new("who").required(true))
.about("Greetings!"),
hello,
);
repl.run()
}