CliApp

Struct CliApp 

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

Built CLI/REPL application

Created by CliBuilder::build(). Provides methods to run the application in different modes:

  • run() - Auto-detect CLI vs REPL based on arguments
  • run_cli() - Force CLI mode with specific arguments
  • run_repl() - Force REPL mode

§Example

use dynamic_cli::prelude::*;

let app = CliBuilder::new()
    .config_file("commands.yaml")
    .context(Box::new(MyContext::default()))
    .register_handler("handler", Box::new(MyHandler))
    .build()?;

// Auto-detect mode (CLI if args provided, REPL otherwise)
app.run()

Implementations§

Source§

impl CliApp

Source

pub fn run_cli(self, args: Vec<String>) -> Result<()>

Run in CLI mode with provided arguments

Executes a single command and exits.

§Arguments
  • args - Command-line arguments (typically from env::args().skip(1))
§Returns
  • Ok(()) on successful execution
  • Err(...) on parse, validation, or execution errors
§Example
// Run with specific arguments
app.run_cli(vec!["command".to_string(), "arg1".to_string()])
Source

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

Run in REPL mode

Enters an interactive loop that continues until the user exits.

§Returns
  • Ok(()) when user exits normally
  • Err(...) on critical errors (e.g., rustyline initialization failure)
§Example
// Start interactive REPL
app.run_repl()
Source

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

Run with automatic mode detection

Decides between CLI and REPL based on command-line arguments:

  • If arguments provided → CLI mode
  • If no arguments → REPL mode

This is the recommended method for most applications.

§Returns
  • Ok(()) on successful execution
  • Err(...) on errors
§Example
// Auto-detect: CLI if args, REPL if no args
app.run()

Trait Implementations§

Source§

impl Debug for CliApp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for CliApp

§

impl !RefUnwindSafe for CliApp

§

impl Send for CliApp

§

impl Sync for CliApp

§

impl Unpin for CliApp

§

impl !UnwindSafe for CliApp

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.