This repository was archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
docs and crates to support re-parsing the command line (readline style) #69
Copy link
Copy link
Open
Description
Using the below crates it's possible to re-parse StructOpt/clap::App objects:
rustylineshlex
Rough example (copy/pasted from my novault application):
let mut rl = rustyline::Editor::<()>::new();
loop {
eprintln!("\nType \"help\" for help and \"exit\" to exit.");
let readline = match rl.readline(">> ") {
Ok(l) => l,
Err(e) => {
eprintln!("Got {}", e);
exit(0);
}
};
let line = readline.trim();
if line.to_ascii_uppercase() == "EXIT" {
exit(0);
}
let mut args = match shlex::split(&readline) {
Some(a) => a,
None => {
eprintln!("Invalid shell syntax");
continue;
}
};
args.insert(0, "novault".into());
let matches = match super::LoopOpt::clap().get_matches_from_safe(args) {
Ok(m) => m,
Err(err) => {
eprintln!("{}", err);
continue;
}
};
if let Err(err) = super::run_cmd_single(global, LoopOpt::from_clap(matches).cmd) {
eprintln!("{}", err);
}
Metadata
Metadata
Assignees
Labels
No labels