Struct yaccas::arguments::Flag [] [src]

pub struct Flag(_);

An argument which represents an option which may occur 0 - x times.

Example

use yaccas::arguments::{Argument, Flag};
use yaccas::parser::{Parser, Result};
use yaccas::scanner::Unix;

// This option will be modified by the flag
let mut will_be_true = false;

{
    let mut parser = Parser::default();
    let flag = Flag::default();

    parser.register(&["option", "o"], Argument::with_callback(flag, | flag | {
        // This will only be executed if the parsing was successful.
        will_be_true = flag.is_activated();
    }));

    assert_eq!(parser.parse(Unix::new(&["-option"])), Result::Success(Vec::new()));
}

assert_eq!(will_be_true, true);Run

Methods

impl Flag
[src]

Activates the flag and increments the counter of matches by 1.

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

Trait Implementations

impl Default for Flag
[src]

Returns the "default value" for a type. Read more

impl Parsable for Flag
[src]