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: InputArgsParserImplementations§
Source§impl FliCallbackData
impl FliCallbackData
Sourcepub fn new(
command: FliCommand,
option_parser: CommandOptionsParser,
arguments: Vec<String>,
arg_parser: InputArgsParser,
) -> Self
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 executedoption_parser- Parser containing all parsed optionsarguments- Positional arguments passed to the commandarg_parser- The argument parser with full parse state
§Note
This is typically created internally by the framework. Users rarely need to construct this manually.
Sourcepub fn get_option_value(&self, name: &str) -> Option<&ValueTypes>
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 providedNone- 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");Sourcepub fn get_argument_at(&self, index: usize) -> Option<&String>
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 indexNone- 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")Sourcepub fn get_arguments(&self) -> &Vec<String>
pub fn get_arguments(&self) -> &Vec<String>
Sourcepub fn get_command(&self) -> &FliCommand
pub fn get_command(&self) -> &FliCommand
Returns a reference to the command being executed.
§Returns
A reference to the FliCommand that matched this execution
Sourcepub fn get_arg_parser(&self) -> &InputArgsParser
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
impl Clone for FliCallbackData
Source§fn clone(&self) -> FliCallbackData
fn clone(&self) -> FliCallbackData
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FliCallbackData
impl RefUnwindSafe for FliCallbackData
impl Send for FliCallbackData
impl Sync for FliCallbackData
impl Unpin for FliCallbackData
impl UnwindSafe for FliCallbackData
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