Crates.io | reedline-repl-rs |
lib.rs | reedline-repl-rs |
version | 1.2.1 |
source | src |
created_at | 2022-06-05 15:20:32.42303 |
updated_at | 2024-08-01 08:53:05.848751 |
description | Library to generate a fancy REPL for your application based on reedline and clap |
homepage | https://github.com/arturh85/reedline-repl-rs |
repository | https://github.com/arturh85/reedline-repl-rs |
max_upload_size | |
id | 600201 |
size | 124,093 |
Library to help you create a fancy REPL for your application based on nushell's reedline.
Features:
shlex
for optional POSIX compliant line splittingCTRL+R
, clear input with CTRL+C
, exit repl with CTRL+D
Basic example code:
//! 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.get_one::<String>("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()
}
Running the example above:
Welcome to MyApp
MyApp〉help
MyApp v0.1.0: My very cool app
COMMANDS:
hello Greetings!
help Print this message or the help of the given subcommand(s)
MyApp〉help hello
hello
Greetings!
USAGE:
hello <who>
ARGS:
<who>
OPTIONS:
-h, --help Print help information
MyApp〉hello Friend
Hello, Friend
MyApp〉
cargo test --features async
Will run the doc tests (compiling the examples). Notice, the examples/async.rs
requires the async
feature.
Forked from repl-rs by Jacklund, changed to use reedline which is an advanced readline clone and the base of nushell.