[][src]Function xflag::parse

pub fn parse<C: IntoIterator>(args: C) -> FlagResult<Arguments> where
    C::Item: AsRef<OsStr>, 

Parse flags from a type that can be turned into an iterator, for example a Vec, and return a sequence of arguments.

To find if an argument is present:

let flags = xflag::parse(vec!["-h"]).unwrap();

Finding the first option:

use xflag::{Argument, parse};

let flags = parse(vec!["-fbar"]).unwrap();
assert_eq!(flags.first('f'), Some(&Argument::Option('f', "bar".into())));

To cycle through the arguments:

for arg in xflag::parse(vec!["-z", "-fbar", "baz", "+42", "-"]).unwrap() {
	println!("{}", arg);

Asserting a particular order to the arguments:

use xflag::{Argument, parse};

let args = parse(vec!["-z", "-fbar", "baz", "+42", "-"]).unwrap();
let mut iter = args.into_iter();

assert_eq!(iter.next(), Some(Argument::Flag('z')));
assert_eq!(iter.next(), Some(Argument::Option('f', "bar".into())));
assert_eq!(iter.next(), Some(Argument::Free("baz".into())));
assert_eq!(iter.next(), Some(Argument::Line(42)));
assert_eq!(iter.next(), Some(Argument::Stdin));
assert_eq!(iter.next(), None);