Crate rustyrepl

source ·
Expand description

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


  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


First, add rustyrepl to your Cargo.toml file

rustyrepl = "0.2"


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

/// The general CLI, essentially a wrapper for the sub-commands [Command]
#[derive(Parser, Clone, Debug)]
pub struct Cli {
    command: Command,

pub struct CliProcessor {}

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!"),

// 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()))?;

This small program will startup up a REPL with the prompt “>>” which you can interact with

>> help
The general CLI, essentially a wrapper for the sub-commands [Commands]

Usage: repl-interface <COMMAND>

  test  Execute a test command
  help  Print this message or the help of the given subcommand(s)

  -h, --help  Print help


Represents the REPL interface and processing loop