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"));

Methods

impl Command
[src]

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!")
});

Executes the command.

Methods from Deref<Target = Flag>

Checks if the flag is set.

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()));

Trait Implementations

impl Deref for Command
[src]

The resulting type after dereferencing

The method called to dereference a value

impl Parsable for Command
[src]