| Crates.io | getopt3 |
| lib.rs | getopt3 |
| version | 2.6.1-beta.6 |
| created_at | 2023-03-24 17:59:21.846198+00 |
| updated_at | 2025-12-20 19:21:34.327078+00 |
| description | Zero dependency command line argument parser |
| homepage | https://gitlab.com/hsn10/getopt3 |
| repository | https://gitlab.com/hsn10/getopt3.git |
| max_upload_size | |
| id | 819587 |
| size | 64,268 |
Version 2.6.1 MIT Licensed
unsafe Rust.let g = getopt3::new(arguments, optstring)
getopt3::new constructor arguments:
std::env::args() but you need to skip the first
argument because it's the executable name.
It can be done manually by .skip(1) or by calling hideBin
utility function which strips the first argument.AsRef <str>. optstring is containing the legitimate option characters.
Valid option characters are alphanumeric, plus '?'.
If such a character is followed by a colon, the option requires an
argument.Result <getopt>.Result wraps parsing errors and getopt structure.getopt structure returned by constructor has following public members:
Vec <String> command line arguments with options removedHashMap <char, bool> map of recognized options. option -> has_argumentHashMap <char, String> options parsed. If option does not have an argument,
it is mapped to an empty "" String,
otherwise it is mapped to its argument as String.Structure getopt supports IntoIterator and can transform itself into Iterator
over supplied command line arguments.
It supports consuming itself or use self immutable reference for enumerating arguments.
getopt.iter() returns Iterator command line arguments without consuming itself.
It is a convenience shortcut for getopt.arguments.iter().
getopt.len() returns number of command line arguments. It is a convenience shortcut for getopt.arguments.len().
getopt.get() returns value of command line option. It is a convenience shortcut for getopt.options.get().
getopt.has() returns if option got supplied on command line. It is a convenience shortcut for getopt.options.contains_key().
getopt[usize] returns nth command line argument. It is a convenience shortcut for getopt.arguments.index().
getopt.is_empty() returns if any arguments were supplied on command line. It is a convenience shortcut for getopt.arguments.is_empty().
You can run strict parse checks by calling validate(getopt) function.
This function returns back Result with supplied getopt instance on success or
error as String. It can detect if unknown options were encountered or
required arguments are missing.
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(arg) = g.options.get(&'b') {
// handle b argument stored in arg
};
};
Some code for these features exists, but development is paused.
Partially implemented code is not compiled in during normal build and can't be enabled in stock crate using features.
no_std Rust version in development.posix strict mode. First non option stops option parsing. This is needed for parsing nested command lines.