aboutsummaryrefslogtreecommitdiff
path: root/vendor/clap/examples/repl.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/clap/examples/repl.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/clap/examples/repl.rs')
-rw-r--r--vendor/clap/examples/repl.rs92
1 files changed, 0 insertions, 92 deletions
diff --git a/vendor/clap/examples/repl.rs b/vendor/clap/examples/repl.rs
deleted file mode 100644
index d0baaed..0000000
--- a/vendor/clap/examples/repl.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-use std::io::Write;
-
-use clap::Command;
-
-fn main() -> Result<(), String> {
- loop {
- let line = readline()?;
- let line = line.trim();
- if line.is_empty() {
- continue;
- }
-
- match respond(line) {
- Ok(quit) => {
- if quit {
- break;
- }
- }
- Err(err) => {
- write!(std::io::stdout(), "{err}").map_err(|e| e.to_string())?;
- std::io::stdout().flush().map_err(|e| e.to_string())?;
- }
- }
- }
-
- Ok(())
-}
-
-fn respond(line: &str) -> Result<bool, String> {
- let args = shlex::split(line).ok_or("error: Invalid quoting")?;
- let matches = cli()
- .try_get_matches_from(args)
- .map_err(|e| e.to_string())?;
- match matches.subcommand() {
- Some(("ping", _matches)) => {
- write!(std::io::stdout(), "Pong").map_err(|e| e.to_string())?;
- std::io::stdout().flush().map_err(|e| e.to_string())?;
- }
- Some(("quit", _matches)) => {
- write!(std::io::stdout(), "Exiting ...").map_err(|e| e.to_string())?;
- std::io::stdout().flush().map_err(|e| e.to_string())?;
- return Ok(true);
- }
- Some((name, _matches)) => unimplemented!("{name}"),
- None => unreachable!("subcommand required"),
- }
-
- Ok(false)
-}
-
-fn cli() -> Command {
- // strip out usage
- const PARSER_TEMPLATE: &str = "\
- {all-args}
- ";
- // strip out name/version
- const APPLET_TEMPLATE: &str = "\
- {about-with-newline}\n\
- {usage-heading}\n {usage}\n\
- \n\
- {all-args}{after-help}\
- ";
-
- Command::new("repl")
- .multicall(true)
- .arg_required_else_help(true)
- .subcommand_required(true)
- .subcommand_value_name("APPLET")
- .subcommand_help_heading("APPLETS")
- .help_template(PARSER_TEMPLATE)
- .subcommand(
- Command::new("ping")
- .about("Get a response")
- .help_template(APPLET_TEMPLATE),
- )
- .subcommand(
- Command::new("quit")
- .alias("exit")
- .about("Quit the REPL")
- .help_template(APPLET_TEMPLATE),
- )
-}
-
-fn readline() -> Result<String, String> {
- write!(std::io::stdout(), "$ ").map_err(|e| e.to_string())?;
- std::io::stdout().flush().map_err(|e| e.to_string())?;
- let mut buffer = String::new();
- std::io::stdin()
- .read_line(&mut buffer)
- .map_err(|e| e.to_string())?;
- Ok(buffer)
-}