[][src]Function go_flag::parse_args

pub fn parse_args<'a, T, S: AsRef<OsStr>, F>(
    args: &[S],
    f: F
) -> Result<Vec<T>, FlagError> where
    T: FlagValue,
    F: FnOnce(&mut FlagSet<'a>), 

Parses the given arguments into flags.

Flags are registered in the given closure.

Returns

Returns the list of positional arguments (remaining arguments).

Positional arguments can also be parsed. You'll typically need Vec<String>, Vec<OsString> or Vec<PathBuf>.

Errors

It returns Err if the given arguments contains invalid flags.

Example

let mut force = false;
let mut lines = 10_i32;
let args = ["-f", "--", "foo"];
let args: Vec<String> = go_flag::parse_args(&args, |flags| {
    flags.add_flag("f", &mut force);
    flags.add_flag("lines", &mut lines);
})?;
assert_eq!(force, true);
assert_eq!(lines, 10);
assert_eq!(args, vec![String::from("foo")]);