pub fn parse<'a, T, F>(f: F) -> Vec<T>
Expand description
Parses the command-line 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>
.
§Exits
It exits if the command-line arguments contain invalid flags.
§Outputs
It prints errors and warnings to the standard error stream (stderr).
§Example
let mut force = false;
let mut lines = 10_i32;
let args: Vec<String> = go_flag::parse(|flags| {
flags.add_flag("f", &mut force);
flags.add_flag("lines", &mut lines);
});
Examples found in repository?
More examples
examples/someflags.rs (lines 6-9)
3fn main() {
4 let mut force = false;
5 let mut lines = 10_i32;
6 let args: Vec<OsString> = go_flag::parse(|flags| {
7 flags.add_flag("f", &mut force);
8 flags.add_flag("lines", &mut lines);
9 });
10 println!("force = {:?}", force);
11 println!("lines = {:?}", lines);
12 for arg in &args {
13 println!("{}", arg.to_string_lossy());
14 }
15}