Struct yaccas::arguments::Command
[−]
[src]
pub struct Command { /* fields omitted */ }
An argument which may influence the parsing process.
Example
use yaccas::arguments::{Argument, Command, AbortReason}; use yaccas::parser::{Parser, Result}; use yaccas::scanner::Unix; let mut parser = Parser::default(); let command = Command::new(|| Some("help")); parser.register(&["help", "h"], Argument::with_callback(command, | command | { // Fallback: Command was not executed OR command has not abort the execution. })); assert_eq!(parser.parse(Unix::new(&["-help"])), Result::Aborted("help"));Run
Methods
impl Command
[src]
fn new<F: Fn() -> AbortReason + 'static>(on_execution: F) -> Command
Creates a new command.
Example
use yaccas::arguments::Command; let command = Command::new(|| { // This code gets executed if the command is parsed. Some("This will abort the parsing process!") });Run
fn execute(&mut self) -> AbortReason
Executes the command.
Methods from Deref<Target=Flag>
fn is_activated(&self) -> bool
Checks if the flag is set.
fn get_matches(&self) -> u32
Returns how many times the flag was set.
Example
use yaccas::arguments::{Argument, Flag}; use yaccas::parser::{Parser, Result}; use yaccas::scanner::Unix; let mut parser = Parser::default(); let flag = Flag::default(); parser.register(&["option", "o"], Argument::with_callback(flag, | flag | { assert_eq!(flag.get_matches(), 2u32); })); assert_eq!(parser.parse(Unix::new(&["-option", "-o"])), Result::Success(Vec::new()));Run
Trait Implementations
impl Deref for Command
[src]
type Target = Flag
The resulting type after dereferencing
fn deref(&self) -> &Flag
The method called to dereference a value