Skip to main content

ReplInterface

Struct ReplInterface 

Source
pub struct ReplInterface { /* private fields */ }
Expand description

REPL (Read-Eval-Print Loop) interface

Provides an interactive command-line interface with:

  • Line editing and history
  • Per-application persistent command history
  • Tab completion (commands, aliases, option flags)
  • Graceful error handling
  • Special commands (exit, quit, –help)

§Architecture

User input → rustyline (DcliHelper) → ReplParser → CommandExecutor → Handler
                   ↓                                      ↓
            Tab completion                         ExecutionContext
         (commands + flags)

§Special Commands

The REPL recognizes these built-in commands:

  • exit, quit — Exit the REPL
  • --help, -h — Show application-level help (if a formatter is attached)
  • <cmd> --help, --help <cmd> — Show per-command help

§History

Command history is stored per application under the XDG data directory:

  • Linux/macOS: ~/.local/share/<app_name>/history
  • Windows: %LOCALAPPDATA%\<app_name>\history

Lines containing a secure: true argument are never written to history. Lines that fail to parse are discarded silently.

Implementations§

Source§

impl ReplInterface

Source

pub fn new( registry: CommandRegistry, context: Box<dyn ExecutionContext>, prompt: String, config: Option<CommandsConfig>, help_formatter: Option<Box<dyn HelpFormatter>>, ) -> Result<Self>

Create a new REPL interface.

All configuration is supplied at construction time so that the tab-completion engine and the help formatter share the same data without duplication.

§Arguments
  • registry — Command registry with all registered commands.
  • context — Execution context passed to handlers.
  • prompt — Prompt prefix (e.g., "myapp" displays as "myapp > ").
  • config — Application configuration for completion and help. Pass None to disable both features.
  • help_formatter — Help formatter implementation. Pass None to use [DefaultHelpFormatter] lazily, or supply a custom implementation.
§Errors

Returns an error if rustyline initialisation fails (rare).

§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;

let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());

// Without completion or help:
let repl = ReplInterface::new(registry, context, "myapp".to_string(), None, None)?;
Source

pub fn run(self) -> Result<()>

Run the REPL loop.

Enters an interactive loop that:

  1. Displays the prompt
  2. Reads user input (with tab completion)
  3. Parses and executes the command
  4. Displays results or errors
  5. Repeats until the user exits
§Returns
  • Ok(()) when the user exits normally (via exit or quit)
  • Err(_) on critical errors (I/O failures, etc.)
§Example
use dynamic_cli::interface::ReplInterface;
use dynamic_cli::prelude::*;

let registry = CommandRegistry::new();
let context = Box::new(MyContext::default());

let repl = ReplInterface::new(registry, context, "myapp".to_string(), None, None)?;
repl.run()?;

Trait Implementations§

Source§

impl Drop for ReplInterface

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.