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
impl ReplInterface
Sourcepub fn new(
registry: CommandRegistry,
context: Box<dyn ExecutionContext>,
prompt: String,
config: Option<CommandsConfig>,
help_formatter: Option<Box<dyn HelpFormatter>>,
) -> Result<Self>
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. PassNoneto disable both features.help_formatter— Help formatter implementation. PassNoneto 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)?;Sourcepub fn run(self) -> Result<()>
pub fn run(self) -> Result<()>
Run the REPL loop.
Enters an interactive loop that:
- Displays the prompt
- Reads user input (with tab completion)
- Parses and executes the command
- Displays results or errors
- Repeats until the user exits
§Returns
Ok(())when the user exits normally (viaexitorquit)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
impl Drop for ReplInterface
Auto Trait Implementations§
impl Freeze for ReplInterface
impl !RefUnwindSafe for ReplInterface
impl !Send for ReplInterface
impl !Sync for ReplInterface
impl Unpin for ReplInterface
impl UnsafeUnpin for ReplInterface
impl !UnwindSafe for ReplInterface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more