1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) Sean Lawlor
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//! rustyrepl is a simple read, evaluate, print, loop processor based on [clap] and utilizing
//! [rustyline].
//!
//! You simply need to define your command structure in a [clap::Parser] derived
//! struct and the processing logic, and the Repl will handle
//!
//! # Purpose
//!
//! 1. Capturing exits/quits of the REPL interface
//! 2. Storing and managing REPL history commands as well as an index of said commands for you
//! 3. Allowing operators to get a help menu at any point, using the full Clap supported help interface (i.e. sub-command help as well)
//! 4. Processing the commands as incoming
//!
//! # Usage
//!
//! First, add rustyrepl to your Cargo.toml file
//!
//! ```toml
//! [dependencies]
//! rustyrepl = "0.2"
//! ```
//!
//! Next:
//!
//! ```rust
//! use anyhow::Result;
//! use clap::{Parser, Subcommand};
//! use rustyrepl::{Repl, ReplCommandProcessor};
//!
//! /// The enum of sub-commands supported by the CLI
//! #[derive(Subcommand, Clone, Debug)]
//! pub enum Command {
//! /// Execute a test command
//! Test,
//! }
//!
//! /// The general CLI, essentially a wrapper for the sub-commands [Command]
//! #[derive(Parser, Clone, Debug)]
//! pub struct Cli {
//! #[clap(subcommand)]
//! command: Command,
//! }
//!
//! #[derive(Debug)]
//! pub struct CliProcessor {}
//!
//! #[async_trait::async_trait]
//! impl ReplCommandProcessor<Cli> for CliProcessor {
//! fn is_quit(&self, command: &str) -> bool {
//! matches!(command, "quit" | "exit")
//! }
//!
//! async fn process_command(&self, command: Cli) -> Result<()> {
//! match command.command {
//! Command::Test => println!("A wild test appeared!"),
//! }
//! Ok(())
//! }
//! }
//!
//! // MAIN //
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let processor: Box<dyn ReplCommandProcessor<Cli>> = Box::new(CliProcessor {});
//!
//! let mut repl = Repl::<Cli>::new(processor, None, Some(">>".to_string()))?;
//! repl.process().await
//! }
//! ```
//!
//! This small program will startup up a REPL with the prompt ">>" which you can interact with
//!
//! ```text
//! >> help
//! The general CLI, essentially a wrapper for the sub-commands [Commands]
//!
//! Usage: repl-interface <COMMAND>
//!
//! Commands:
//! test Execute a test command
//! help Print this message or the help of the given subcommand(s)
//!
//! Options:
//! -h, --help Print help
//!
//! ```
pub
pub use crateReplCommandProcessor;
pub use crateRepl;