FliCallbackData

Struct FliCallbackData 

Source
pub struct FliCallbackData {
    pub command: FliCommand,
    pub option_parser: CommandOptionsParser,
    pub arguments: Vec<String>,
    pub arg_parser: InputArgsParser,
}
Expand description

Context data passed to command callbacks containing parsed arguments and options.

This struct provides a convenient API for accessing parsed command-line data without dealing with raw argument vectors.

§Examples

fn my_command(data: &FliCallbackData) {
    let name = data.get_option_value("name")
        .and_then(|v| v.as_str())
        .unwrap_or("World");
    println!("Hello, {}!", name);
}

Fields§

§command: FliCommand§option_parser: CommandOptionsParser§arguments: Vec<String>§arg_parser: InputArgsParser

Implementations§

Source§

impl FliCallbackData

Source

pub fn new( command: FliCommand, option_parser: CommandOptionsParser, arguments: Vec<String>, arg_parser: InputArgsParser, ) -> Self

Creates a new callback data context.

§Arguments
  • command - The command being executed
  • option_parser - Parser containing all parsed options
  • arguments - Positional arguments passed to the command
  • arg_parser - The argument parser with full parse state
§Note

This is typically created internally by the framework. Users rarely need to construct this manually.

Source

pub fn get_option_value(&self, name: &str) -> Option<&ValueTypes>

Retrieves the parsed value for a given option name.

Supports multiple lookup formats:

  • With dashes: “-v”, “–verbose”
  • Without dashes: “v”, “verbose”
§Arguments
  • name - The option name (with or without dashes)
§Returns
  • Some(&ValueTypes) - The parsed value if the option was provided
  • None - If the option wasn’t provided or doesn’t exist
§Examples
// All of these work:
data.get_option_value("name");
data.get_option_value("-n");
data.get_option_value("--name");
Source

pub fn get_argument_at(&self, index: usize) -> Option<&String>

Retrieves a positional argument by index.

§Arguments
  • index - Zero-based index of the argument
§Returns
  • Some(&String) - The argument at the given index
  • None - If index is out of bounds
§Examples
// For command: myapp copy file1.txt file2.txt
let source = data.get_argument_at(0);  // Some("file1.txt")
let dest = data.get_argument_at(1);    // Some("file2.txt")
Source

pub fn get_arguments(&self) -> &Vec<String>

Returns all positional arguments as a vector.

§Returns

A reference to the vector of all positional arguments

§Examples
for arg in data.get_arguments() {
    println!("Argument: {}", arg);
}
Source

pub fn get_command(&self) -> &FliCommand

Returns a reference to the command being executed.

§Returns

A reference to the FliCommand that matched this execution

Source

pub fn get_arg_parser(&self) -> &InputArgsParser

Returns a reference to the argument parser.

Provides access to low-level parsing details if needed.

§Returns

A reference to the InputArgsParser used for parsing

Trait Implementations§

Source§

impl Clone for FliCallbackData

Source§

fn clone(&self) -> FliCallbackData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FliCallbackData

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.