pub fn getopt_long(opts: &[Opt]) -> OptResult<Arguments>Examples found in repository?
examples/ex1/main.rs (line 18)
7fn main() -> OptResult<()> {
8 let longopts = &[
9 Opt::new(None, Some('v'), HasArg::NoArgument, "show version.").unwrap(),
10 Opt::new(None, Some('h'), HasArg::NoArgument, "help information.").unwrap(),
11 Opt::new(None, Some('a'), HasArg::RequiredArgument, "add record to table.").unwrap(),
12 Opt::new(None, Some('r'), HasArg::OptionalArgument, "remove record from table.").unwrap(),
13 Opt::new(None, Some('m'), HasArg::NoArgument, "modify the record in table.").unwrap(),
14 Opt::new(None, Some('q'), HasArg::NoArgument, "query the table.").unwrap(),
15 ];
16
17 usage("ex1", "this is ex1 example.", env!("CARGO_PKG_VERSION"), longopts);
18 let p = getopt_long(longopts)?;
19 println!("{}", p);
20 Ok(())
21}More examples
examples/ex2/main.rs (line 18)
7fn main() -> OptResult<()> {
8 let longopts = &[
9 Opt::new(None, Some('v'), HasArg::NoArgument, "show version.").unwrap(),
10 Opt::new(None, Some('h'), HasArg::NoArgument, "help information.").unwrap(),
11 Opt::new(Some("add".to_owned()), Some('a'), HasArg::RequiredArgument, "add record to table.").unwrap(),
12 Opt::new(Some("remove".to_owned()), Some('r'), HasArg::OptionalArgument, "remove record from table.").unwrap(),
13 Opt::new(Some("modify".to_owned()), Some('m'), HasArg::NoArgument, "modify the record in table.").unwrap(),
14 Opt::new(Some("query".to_owned()), None, HasArg::NoArgument, "query the table.").unwrap(),
15 ];
16
17 usage("ex2", "this is ex2 example.", env!("CARGO_PKG_VERSION"), longopts);
18 match getopt_long(longopts) {
19 Ok(p) => println!("Arguments:\n{}", p),
20 Err(e) => println!("{}", e),
21 }
22
23 Ok(())
24}