Crate getopt3

Source
Expand description

§getopt(3) parser

§Command line argument parser with GNU parsing rules and double dash ‘–’ support.

getopt3::new parses the command line elements and isolates arguments from options. It returns a getopt structure where you can query options and use isolated arguments.

An element that starts with ‘-’ (and is not exactly “-” or “–”) is an option element. The characters of this element (aside from the initial ‘-’) are option characters. A double dash -- can be used to indicate the end of options; any arguments following it are treated as positional arguments.

§Example
use std::env::args;
use getopt3::hideBin;
let rc = getopt3::new(hideBin(args()), "ab:c");
if let Ok(g) = rc {
   // command line options parsed sucessfully
   if let Some(str) = g.options.get(&'b') {
      // handle b argument
      println!("option -b have {} argument", str);
   };
};
§Reference
  1. POSIX getopt function.
  2. GNU libc getopt function.

Structs§

getopt
Parsed command line options.

Functions§

hideBin
Removes first element from the IntoIterator.
new
Parse command line arguments.
validate
Validate parsed options in strict mode.